I'm new to Xamarin.Forms and unable to bind the service response to WebView.
I have a post view page which has webview in it and the responses I am getting back are combination of texts, Lists and KeyValuePair.
I am actually unable to bind the list responses within that single webview and navigate them to the new related posts that I got as response from the service.
I am attaching the screenshots of the XAML page and the ContentPage cs where I have created the html code to be binded.
This is My XAML Page
This is how I bind the responses and created html
This is how the post looks
I need them to have redirected to a new individual post when I click on any of the links. Right now it shows the complete list view in response with the path it needs to navigate to.
Please help me to understand if I am doing something wrong.
I managed to make it work by concatenating the whole response in string.
Below is the code which helped me achieve this-
String getHtml()
{
var bodyStyle = "body{height: 100%;}p{text-align:left;color:#191919;}filter{background-color:#191919;}a:link"
+ "{color:#2588B0; background-color:transparent}a:visited {color:#0099CC; background-color:transparent}"
+ "a:hover{color:#0099CC; background-color:transparent}a:ative{color:#0099CC; background-color:transparent}span{background-color: yellow;color: black}customRight{float: right}";//window.onload = function(e){ alert('prevented');}
var refs = bodyStyle;
refs = refs + "<center><h4>" + response.Title + "<h4></center>";
if (response.Pc.Count > 0)
{
refs = refs + "<center><u>" + PrimaryCitation +
"</a></u></center><br>";
}
if (string.IsNullOrWhiteSpace(response.Cn))
{
refs = refs + "<center>" + response.Cn + "</center><br>";
}
if (response.Judges.Count() > 0)
{
refs = refs + "<center> <strong>Coram:</strong> " + JudgesN + "</center><br>";
}
if (string.IsNullOrWhiteSpace(response.JGD.ToString()))
{
refs = refs + "<center> <strong>Decided On:</strong> " + response.JGD + "</center><br>";
}
if(string.IsNullOrWhiteSpace(response.AppealType) )
{
refs = refs + "<center> <strong>Appeal Type: </strong>" + response.AppealType + "</center><br>";
}
if (response.Appellants != null)
{
refs = refs + "<left><b>" + Appeallants + "</b></left>";
refs = refs + "<customRight>APPELLANT</customRight><br>";
}
refs = refs + "<center>VERSUS</center>";
if (response.Respondants != null)
{
refs = refs + "<left><b>" + Respondants + "</b></left>";
refs = refs + "<customRight>RESPONDENT</customRight><br><br>";
}
if (string.IsNullOrWhiteSpace(response.FinalVerdict))
{
refs = refs + "<center> <strong>Final Verdict:</strong> " + response.FinalVerdict + "</center><br>";
}
if (string.IsNullOrWhiteSpace(response.Headnote))
{
refs = refs + "<p> <strong>Head Note:</strong><br/> " + response.Headnote.ToLowerInvariant() + "</p><br>";
}
if(response.Refs != null)
{
refs = refs + "<left><b>Refered Jdgmts: </b></left><br>";
foreach(var obj in response.Refs)
{
if(obj.Jid == null) {
refs = refs + "<p style='font-size:13px;'>"
+ obj.Title
+"</p>";
}
/*else
{
refs = refs + "<p style='font-size:13px;'>" + "<a href=\""
+ obj.Jid
+ "\" target=\"_blank\">"
+ obj.Title
+ "</a>"
+ "</p>";
}*/
else
{
refs = refs + "<p style='font-size:13px;'>" + "<a href=\""
+ obj.Jid
+ "\" target=\"_blank\" onClick=\"(function(e){alert('e is here'); loadJt(obj.Jid);return false;})(); return false;\">"
+ obj.Title
+ "</a>"
+ "</p>";
}
if(response.AtRefrs != null)
{
refs = refs + "<left><b>Refered Ats: </b></left><br>";
foreach(var refAt in response.AtRefrs) {
if(refAt.AtId == null) {
refs += "<p style='font-size:13px;'>"
+ refAt.At + "</p>";
}
else
{
refs += "<p style='font-size:13px;'>" + "<a href=\""
+ "#" + refAt.AtId
+ "\" target=\"_blank\">"
+ refAt.At + "</a>";
}
foreach(var refSec in refAt.S) {
if(refSec.Ssi != null) {
refs += " " + refSec.St;
}
else
{
refs += " " + "<a href=\""
+ "#" + (refSec.SId)
+ "\" target=\"_blank\">"
+ refSection.Section
+ "</a>";
}
}
refs += "</p>";
}
}
refs = refs + "<left><b>Jdgmt: </b></left>";
var jdgmt = "<p>" + response.DJdes
+ (response.Text)+ "</p>";
jdgmt = jdgmt.Replace("^^^", "<br/><br/>");
jdgmt = jdgmt.Replace("<SPARA>", "<p>");
jdgmt = jdgmt.Replace("</SPARA>", "</p>");
refs = refs + jdgmt;
refs = refs + "</body></html>";
return refs;
}
data.Source = new HtmlWebViewSource { Html = getHtml(), BaseUrl="http://url.com/", BindingContext = response };
Related
How to obtain the type information of "t"?
How to get the type name of t
class Test
{
void main()
{
var t = new Test();
t.Equals(null);// object.Equals
//How do I get the type of "t" ?
}
}
private static void AnalyzeNode(SyntaxNodeAnalysisContext context)
{
var invocationExpr = (InvocationExpressionSyntax)context.Node;
var memberAccessExpr = invocationExpr.Expression as MemberAccessExpressionSyntax;
if (memberAccessExpr == null)
return;
if (memberAccessExpr.Name.ToString() != nameof(object.Equals))
return;
var memberSymbol = context.SemanticModel.GetSymbolInfo(memberAccessExpr).Symbol as IMethodSymbol;
if (memberSymbol == null)
return;
_ = memberSymbol.ContainingType.SpecialType;// Object
}
I don't know why, but I cannot enter the breakpoint when debugging with vs.
So I can only debug in this way, but I can't find the correct method.
var str = memberSymbol.ContainingSymbol?.Name + Environment.NewLine
+ memberSymbol.AssociatedSymbol?.Name + Environment.NewLine
+ memberSymbol.ContainingType?.Name + Environment.NewLine
+ memberSymbol.ContainingType?.SpecialType + Environment.NewLine
+ memberSymbol.ContainingType?.ContainingType?.Name + Environment.NewLine
+ memberSymbol.ContainingType?.TypeKind + Environment.NewLine
+ memberSymbol.ContainingType?.OriginalDefinition?.Name + Environment.NewLine
+ memberSymbol.ContainingType?.BaseType?.Name + Environment.NewLine
+ memberSymbol.ContainingType?.MetadataName + Environment.NewLine
+ memberSymbol.ContainingType?.ContainingAssembly?.Name + Environment.NewLine
+ string.Join(" ", memberSymbol.ContainingType?.MemberNames ?? Enumerable.Empty<string>()) + Environment.NewLine
+ "***************" + Environment.NewLine
+ invocationExpr.FullSpan.ToString() + Environment.NewLine
;
File.WriteAllText(#"xxxxxxx", str);
I want to obtain "Test" type information or type string
First, I apologize for the length of this, but it's all I knew when I started. Now I'm experimenting with the foreach, List<t> and TreeView classes to avoid repetition as recmomended by SO community.
The form will collect information via text boxes, allow attachments of files with file dialogs and collate all info into a neat HTML bodied email. We sell slabs.. and my original code looked a little like this:
private void PrepareReturnEmailTwoSlabs()
{
LoadSettings();
string Fname = Properties.Settings.Default.FabricatorName;
string Facc = Properties.Settings.Default.FabricatorAccountNo;
string Fadd1 = Properties.Settings.Default.FabricatorAddress1;
string Fadd2 = Properties.Settings.Default.FabricatorAddress2;
string Ftown = Properties.Settings.Default.FabricatorTown;
string Fcounty = Properties.Settings.Default.FabricatorCounty;
string Fpostcode = Properties.Settings.Default.FabricatorPostcode;
string Fphoneno = Properties.Settings.Default.FabricatorPhone;
string Femail = Properties.Settings.Default.FabricatorEmail;
string Fclient = Properties.Settings.Default.ClientManagerEmail;
string Fcentre = Properties.Settings.Default.CentreEmail;
string FQt = Properties.Settings.Default.QTEmail;
string Dateofinv = dateTimePicker1.Value.ToShortDateString();
string Inv = textBox13.Text;
string Material1 = textBox14.Text;
string Thick1 = comboBox8.SelectedValue.ToString();
string Batch1 = textBox44.Text;
string Reason1 = comboBox1.SelectedValue.ToString();
string Notes = textBox18.Text;
string Thick2 = comboBox7.SelectedValue.ToString();
string Material2 = textBox15.Text;
string Batch2 = textBox45.Text;
string Reason2 = comboBox2.SelectedValue.ToString();
if (Thick2 == null)
{
Thick2 = "not selected";
}
if (Material2 == null)
{
Material2 = "not selected ";
}
if (Batch2 == null)
{
Batch2 = "not selected ";
}
if (Reason2 == null)
{
Reason2 = "not selected ";
}
GenerateUniqueRefReturn();
//construct email
var message = new MimeMessage();
message.From.Add(new MailboxAddress("************", "***************"));
message.To.Add(new MailboxAddress("**********", "********"));
message.Subject = "Return" + " " + Returnid;
//different message bodies dependant on how many slabs are chosen
TextPart body2 = new TextPart("html")
{
Text = #"Please See Below Information" + "<br/>" +
"<h4>Return ID: " + " " + Returnid + "</h4>" + "<br/>" +
"<b>Fabricator Name:</b>" + " " + Fname + "<br/>" + Environment.NewLine +
"<b>Account Number:</b>" + " " + Facc + "<br/>" + Environment.NewLine +
"<b>Address Line 1:</b>" + " " + Fadd1 + "<br/>" + Environment.NewLine +
"<b>Address Line 2:</b>" + " " + Fadd2 + "<br/>" + Environment.NewLine +
"<b>Town:</b>" + " " + Ftown + "<br/> " + Environment.NewLine +
"<b>County:</b>" + " " + Fcounty + "<br/>" + Environment.NewLine +
"<b>Postcode:</b>" + " " + Fpostcode + "<br/>" + Environment.NewLine +
"<b>Phone:</b>" + " " + Fphoneno + "<br/>" + Environment.NewLine +
"<b>Email:</b>" + " " + Femail + "<br/>" + Environment.NewLine + "<br/>" +
"<br/>" +
"<b>Date Of Invoice: </b>" + " " + DoI + "<br/>" +
"<b>Invoice: </b>" + " " + Inv + "<br/>" +
"<b>Material Information:</b>" + "<br/>" +
//slab 1
"<b>Thickness: </b>" + " " + Thick1 + "mm" + "<br/>" +
"<b>Material Name: </b>" + " " + Material1 + "<br/>" +
"<b>Batch No: </b>" + " " + Batch1 + "<br/>" +
"<b>Reason for Return: </b>" + " " + Reason1 + "<br/>" + "<br/>" +
//slab 2
"<b>Thickness: </b>" + " " + Thick2 + "mm" + "<br/>" +
"<b>Material Name: </b>" + " " + Material2 + "<br/>" +
"<b>Batch No: </b>" + " " + Batch2 + "<br/>" +
"<b>Reason for Return: </b>" + " " + Reason2 + "<br/>" + "<br/>" +
"<br/>" +
"<b>Notes:" + " " + Notes
};
var builder = new BodyBuilder();
//check for return attachment and if found, assign attachment to message via bodybuilder
if (checkBox5.Checked)
{
builder.TextBody = body2.Text;
builder.HtmlBody = body2.Text;
builder.Attachments.Add(ReturnAttachment1);
message.Body = builder.ToMessageBody();
}
if (checkBox7.Checked)
{
builder.TextBody = body2.Text;
builder.HtmlBody = body2.Text;
builder.Attachments.Add(ReturnAttachment1);
builder.Attachments.Add(ReturnAttachment2);
message.Body = builder.ToMessageBody();
}
if (checkBox6.Checked)
{
builder.TextBody = body2.Text;
builder.HtmlBody = body2.Text;
builder.Attachments.Add(ReturnAttachment1);
builder.Attachments.Add(ReturnAttachment2);
builder.Attachments.Add(ReturnAttachment3);
message.Body = builder.ToMessageBody();
}
else
{
message.Body = body2;
}
//Connection to SMTP and Criteria to Send
using (var client = new SmtpClient())
{
// For demo-purposes, accept all SSL certificates (in case the server supports STARTTLS)
client.ServerCertificateValidationCallback = (s, c, h, e) => true;
client.Connect("smtp.gmail.com", 587, false);
// Note: only needed if the SMTP server requires authentication
client.Authenticate("***************#********.com", "*********");
client.Send(message);
client.Disconnect(true);
This code was repeated all the way up to five slabs. So now, I have a class:
{
public string Thickness { get; set; }
public string Material { get; set; }
public string Batch { get; set; }
public Slab(string Thick, string Mat, string Batchno)
{
Thickness = Thick;
Material = Mat;
Batch = Batchno;
}
}
A List that holds this object:
private void button1_Click(object sender, EventArgs e)
{
string t = comboBox1.SelectedValue.ToString();
string m = comboBox2.SelectedValue.ToString();
string b = textBox6.Text;
Slab S = new Slab(t, m, b);
allSlabs.Add(S);
PaintTree();
}
public void PaintTree()
{
int ParentIndex;
TreeSlabs.Nodes.Clear();
foreach (Slab slab in allSlabs)
{
TreeSlabs.BeginUpdate();
TreeSlabs.Nodes.Add("Slab" + " " + (allSlabs.IndexOf(slab) + 1).ToString());
ParentIndex = allSlabs.IndexOf(slab);
TreeSlabs.Nodes[ParentIndex].Nodes.Add("Thickness: " + $"{slab.Thickness}");
TreeSlabs.Nodes[ParentIndex].Nodes.Add("Material: " + $"{slab.Material}");
TreeSlabs.Nodes[ParentIndex].Nodes.Add("Batch: " + $"{slab.Batch}");
TreeSlabs.EndUpdate();
}
}
Now i want to create a foreach.. that iterates through each node.. and collects the info from the parent and its children foreach node, and somehow instantiate new HTML methods for each node..
Foreach Node:
Compose HTML Line - new HTML
Slab 1:
Thickness:
Material
Batch
Slab 2:... etc
If theres 8 nodes, it generates 8 of those bodies. i can think of ways.. but i KNOW they're defintely not the correct ways to go about it based on what ive read and seen out there.
Many Thanks
You don't need to iterate through the tree and try to reclaim the data you put into it from the List of Slabs; it would be simpler to enumerate the List:
By the way, some other tips:
don't beginupdate/endupdate inside the loop, do it outside
the Add method that adds a node to a tree returns the node it added; you don't have to find it again by index, just capture it var justAdded = rootnode.Add("parent node"); and then add your thickness etc to it justAdded.Nodes.Add("thickness..."). The only add command that doesn't return the added mode is the one that takes a treenode type object; it doesn't need to return it because you already have it
consider adding a method to your slab to return some html, to simplify things
you can tidy all that html up with some string interpolation like you did with your $"{slab.thickness}" etc
Anyone has an idea of how I can make this less redundant? I need to populate the inner html of multiple div elements on the client with the same content.
Client:
<div id="projectList_dialog1" class="listView" runat="server"></div>
<div id="projectList_dialog2" class="listView" runat="server"></div>
Code Behind:
protected void loadProjectList()
{
var projectsPath = userDataPath + #"\" + username + #"\Projects";
if (Directory.Exists(projectsPath))
{
var projects = Directory.GetDirectories(userDataPath + #"\" + username + #"\Projects");
projectList_dialog1.InnerHtml = "<table>";
projectList_dialog2.InnerHtml = "<table>";
projectList_dialog1.InnerHtml += "<tr><td>Name</td><td>Date modified</td></tr>";
projectList_dialog2.InnerHtml += "<tr><td>Name</td><td>Date modified</td></tr>";
List<string> storedProjectNamesList = new List<string>();
for (var i = 0; i < projects.Length; i++)
{
var storedProjectName = projects[i].Remove(0, projects[i].LastIndexOf('\\') + 1);
storedProjectNamesList.Add('"' + storedProjectName + '"');
var lastModified = System.IO.File.GetLastWriteTime(storedProjectName);
projectList_dialog1.InnerHtml += "<tr class='" + storedProjectName + "' onclick='listViewAction(event)'><td>" + storedProjectName + "</td><td>" + lastModified + "</td></tr>";
projectList_dialog2.InnerHtml += "<tr class='" + storedProjectName + "' onclick='listViewAction(event)'><td>" + storedProjectName + "</td><td>" + lastModified + "</td></tr>";
}
projectList_dialog1.InnerHtml += "</table>";
projectList_dialog2.InnerHtml += "</table>";
storedProjectNames = string.Join(",", storedProjectNamesList);
}
else
{
serverMessage.InnerHtml = "Code (0x3): The system cannot find the path specified.";
}
}
Assign the data to a local variable like innerHtml, only change InnerHtml of the elements once
protected void loadProjectList()
{
var projectsPath = userDataPath + #"\" + username + #"\Projects";
if (Directory.Exists(projectsPath))
{
var projects = Directory.GetDirectories(userDataPath + #"\" + username + #"\Projects");
//create a variable
var innerHtml = "<table><tr><td>Name</td><td>Date modified</td></tr>";
List<string> storedProjectNamesList = new List<string>();
for (var i = 0; i < projects.Length; i++)
{
var storedProjectName = projects[i].Remove(0, projects[i].LastIndexOf('\\') + 1);
storedProjectNamesList.Add('"' + storedProjectName + '"');
var lastModified = System.IO.File.GetLastWriteTime(storedProjectName);
//add to that variable
innerHtml += "<tr class='" + storedProjectName + "' onclick='listViewAction(event)'><td>" + storedProjectName + "</td><td>" + lastModified + "</td></tr>";
}
innerHtml += "</table>";
//NOW set innerhtml on the objects
projectList_dialog1.InnerHtml = innerHtml;
projectList_dialog2.InnerHtml = innerHtml;
storedProjectNames = string.Join(",", storedProjectNamesList);
}
else
{
serverMessage.InnerHtml = "Code (0x3): The system cannot find the path specified.";
}
}
i have a problem concerning a breadcrumb navigation.
In my application i have a Start.aspx where i build a navigation menu for the next module (control1.ascx, control2.ascx, ...) which should be loaded after clicking.
This ascx contains a grid with some data rows and link buttons to load other ascx on the start page
This is the common way the app works.
Now i need to visualize which ascx is loaded in the breadcrumb
Maybe we can viaualize it like this:
Start.aspx -> control1.ascx -> control1_1.ascx
Right now the app would be on the lowest level and if i click on "control1.ascx" this control should be loaded again or if i choose Start.aspx the "Home" should be loaded.
protected override void Render(HtmlTextWriter output)
{
NavigationDataTable moduleNameList = new NavigationDataTable();
List<usp_GetNavigationElements_Result> ModuleList = moduleNameList.GetModulesList(1, LoggedInUser);
StringBuilder sbResult1 = new StringBuilder();
//string sbResult;
if (Page.Items["title"] != null)
{
string id = Page.Items["title"].ToString();
PageTitle = Page.Items["title"].ToString();
}
//------------------------------------------------------------------------------------------
var request = HttpContext.Current.Request;
System.Collections.Specialized.NameValueCollection coll;
// Load ServerVariable collection into NameValueCollection object.
coll = request.ServerVariables;
string serverName = request.ServerVariables["SERVER_NAME"];
//------------------------------------------------------------------------------------------
string strDomain = "";
if (serverName == "localhost")
{
//Lokal
strDomain = "localhost:49573";
}
else
{
//Intranet
strDomain = "i";
}
string strURL = "/Start.aspx";
string strDirs = "control1.ascx";
Separator3 = new Image();
Separator3.Height = 52;
Separator3.Width = 52;
ArrowSeparator = new Image();
ArrowSeparator.ImageUrl = "/img/mb_arrow_separator.png";
HomeSymbol = new Image();
HomeSymbol.ImageUrl = "/img/mb_home.png";
// Home-Navigation for Start
sbResult1.Append("<img src='" + HomeSymbol.ImageUrl + "'>");
sbResult1.Append("<a href='http://" + strDomain + "/modules" + strURL + "'style='text-decoration:none;'>" + RootName + " " + "</a>");
sbResult1.Append("<img src='" + ArrowSeparator.ImageUrl + "' hspace='10'>");
//-------------------------------------------------------------------------------------------------------------------------------
foreach (var item in ModuleList)
{
if (HttpContext.Current.Session["ModuleTitle"] != null)
{
if (item.ModuleTitle == HttpContext.Current.Session["ModuleTitle"].ToString() )
{
//sbResult1.Append("<a href='http://" + strDomain + "/modules" + strURL + "?" + item.ModuleName + "'>" + item.ModuleTitle + "</a>" + Separator);
Separator3.ImageUrl = "/img/" + HttpContext.Current.Session["ModuleTitle"].ToString() + ".png";
sbResult1.Append("<img src='" + Separator3.ImageUrl + " 'hspace='10'>");
sbResult1.Append(HttpContext.Current.Session["ModuleTitle"]).ToString();
}
}
}
if (!ModuleList.Contains(HttpContext.Current.Session["ModuleTitle"]))
{
if (HttpContext.Current.Session["ModuleTitle"] != null)
{
if (HttpContext.Current.Session["ModuleTitle"].ToString().Contains("_"))//|| HttpContext.Current.Session["ModuleSubTitle"] != null)
{
string[] std = HttpContext.Current.Session["ModuleTitle"].ToString().Split('_');
Separator3.ImageUrl = "/img/" + std[0] + ".png";
sbResult1.Append("<img src='" + Separator3.ImageUrl + "' hspace='10'>");
sbResult1.Append("<a href='http://" + strDomain + "/modules" + strURL + "?" + std[0] + "'style='text-decoration:none;'>" + std[0] + " " + "</a>");
sbResult1.Append("<img src='" + ArrowSeparator.ImageUrl + "' hspace='10'>");
sbResult1.Append("<img src='/img/Prozess.png' hspace='10'>");
sbResult1.Append(std[1]);
}
}
}
//-------------------------------------------------------------------------------------------------------------------------------
output.Write(sbResult1.ToString());
}
Do i have to make this Breadcrumb.cs and override Render() or is there a better way.
Greets DarkGecko
have you considered a SiteMapPath?
<asp:SiteMapPath ID="SiteMapPath1" Runat="server"></asp:SiteMapPath>
https://msdn.microsoft.com/en-us/library/x20z8c51.aspx
I try to insert a word heading at a specific position but it is always added at the end of the document. Where is my mistake?:
foreach (Publish p in tempstructure)
{
if (p.element_type_id == 3)
{
Word.Paragraph par = selection.Paragraphs.Add();
par.Range.Text = "test";
par.Range.set_Style(Word.WdBuiltinStyle.wdStyleHeading2);
par.Range.InsertParagraphAfter();
selection.TypeParagraph();
}
else
{
if (File.Exists(#Properties.Settings.Default.documentsPath + p.filename + "_" + language + ".docx"))
{
selection.InsertFile(#Properties.Settings.Default.documentsPath + p.filename + "_" + language + ".docx");
selection = word.Selection;
}
else
{
selection.TypeText("Missing file: " + p.filename + "_" + language + ".docx");
selection.TypeParagraph();
}
}
selection = word.Selection;
}
Best regards ...
The simple solution is:
foreach (Publish p in tempstructure)
{
if (p.element_type_id == 3)
{
selection.set_Style(Word.WdBuiltinStyle.wdStyleHeading2);
selection.TypeText(p.name);
selection.TypeParagraph();
}
else
{
if (File.Exists(#Properties.Settings.Default.documentsPath + p.filename + "_" + language + ".docx"))
{
selection.InsertFile(#Properties.Settings.Default.documentsPath + p.filename + "_" + language + ".docx");
selection = word.Selection;
}
else
{
selection.TypeText("Missing file: " + p.filename + "_" + language + ".docx");
selection.TypeParagraph();
}
}
selection = word.Selection;
}