MVVMCross Code Snippets for Visual Studio? - mvvmcross

where can I download the snippets for Visual Studio, the likes pf pmvx, cmvx and others?
I though those would be available on the github projects, but can't find them...

I've already created my own. Please remember that these are ReSharper's template.
mvxcom -> for Command
#region $region$ command
private MvxCommand _$NAME$Command;
public ICommand $PNAME$Command
{
get
{
_$NAME$Command = _$NAME$Command ?? new MvxCommand(Do$PNAME$Command);
return _$NAME$Command;
}
}
private void Do$PNAME$Command()
{
$END$
}
#endregion
mvxprop -> for Properties
#region $region$
private $TYPE$ _$NAME$;
public $TYPE$ $PNAME$
{
get { return _$NAME$; }
set { _$NAME$ = value; RaisePropertyChanged(() => $PNAME$); }
}
#endregion
$END$
mvxset -> Binding Set
var set = this.CreateBindingSet<$VIEW$, $VIEW$Model>();
set.Bind($ELEMENT$).To(vm => vm$END$);
set.Apply();
You can add them to your ReSharper using ReSharper>Template Explorer>Live Templates>New Template.
Please feel free to change them however you desire.

And here's the native VS version of the snippets based on Aboo's answer above.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvMCross Property</Title>
<Description>Insert a property block with a backing field and property change notification</Description>
<Shortcut>mvxprop</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>http://stackoverflow.com/questions/18200679/mvvmcross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>propertyName</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip></ToolTip>
<Default>PropertyName</Default>
</Literal>
<Literal>
<ID>propertyType</ID>
<ToolTip></ToolTip>
<Default>int</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private $propertyType$ $backingfield$;
public $propertyType$ $property$
{
get { return $backingfield$; }
set { if($backingfield$ == value) return; $backingfield$ = value; RaisePropertyChanged(() => $property$); }
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvMCross Command</Title>
<Description>Insert a Command declaration for an MvvMCross View Model</Description>
<Shortcut>mvxcom</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>http://stackoverflow.com/questions/18200679/mvvmcross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>commandName</Default>
</Literal>
<Literal>
<ID>Name</ID>
<ToolTip></ToolTip>
<Default>CommandName</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private MvxCommand $backingfield$Command;
public MvxCommand $Name$Command
{
get
{
$backingfield$Command = $backingfield$Command ?? new MvxCommand(Do$Name$Command);
return $backingfield$Command;
}
}
private void Do$Name$Command()
{
$end$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvMCross Binding Set</Title>
<Description>Create a binding set and bind an element</Description>
<Shortcut>mvxset</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>http://stackoverflow.com/questions/18200679/mvvmcross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>viewName</ID>
<ToolTip></ToolTip>
<Default>viewName</Default>
</Literal>
<Literal>
<ID>element</ID>
<ToolTip></ToolTip>
<Default>element</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[var set = this.CreateBindingSet<$viewName$View, $viewName$ViewModel>();
set.Bind($element$).To(vm => vm$end$);
set.Apply();
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

If I'm correct in my presumption, you're referring to the shortcuts that Stuart uses in his demos for MvvmCross. These are snippets of code that he has written and assigned to shortcuts using ReSharper and are not publicly available, though if you asked nicely they can be exported and shared. Of course you could always make your own 'Live Template' using this tutorial

I modified #Coasty's answer to include an async command adapted from https://stackoverflow.com/questions/17187113/how-can-i-use-async-in-an-mvvmcross-view-model and changed the shortcuts so they no longer collide with the mvx namespaces.
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Property</Title>
<Description>Insert a property block with a backing field and property change notification</Description>
<Shortcut>mvvmcrossprop</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>propertyName</Default>
</Literal>
<Literal>
<ID>property</ID>
<ToolTip></ToolTip>
<Default>PropertyName</Default>
</Literal>
<Literal>
<ID>propertyType</ID>
<ToolTip></ToolTip>
<Default>int</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private $propertyType$ $backingfield$;
public $propertyType$ $property$
{
get { return $backingfield$; }
set { $backingfield$ = value; RaisePropertyChanged(() => $property$); }
}
$end$]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Command</Title>
<Description>Insert a Command declaration for an MvvmCross View Model</Description>
<Shortcut>mvvmcrosscom</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>commandName</Default>
</Literal>
<Literal>
<ID>Name</ID>
<ToolTip></ToolTip>
<Default>CommandName</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private MvxCommand $backingfield$Command;
public MvxCommand $Name$Command
{
get
{
$backingfield$ = $backingfield$ ?? new MvxCommand(Do$Name$);
return $backingfield$;
}
}
private void Do$Name$()
{
$end$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Async Command</Title>
<Description>Insert an Async Command declaration for an MvvmCross View Model</Description>
<Shortcut>mvvmcrossacom</Shortcut>
<Author>Benjamin Hysell (based on Andrew Coates Command Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>backingfield</ID>
<ToolTip></ToolTip>
<Default>commandName</Default>
</Literal>
<Literal>
<ID>Name</ID>
<ToolTip></ToolTip>
<Default>CommandName</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[private MvxCommand $backingfield$Command;
public MvxCommand $Name$Command
{
get
{
$backingfield$ = $backingfield$ ?? new MvxCommand(async () => await Do$Name$());
return $backingfield$;
}
}
private async Task Do$Name$()
{
$end$
}
]]>
</Code>
</Snippet>
</CodeSnippet>
<CodeSnippet Format="1.0.0">
<Header>
<Title>MvvmCross Binding Set</Title>
<Description>Create a binding set and bind an element</Description>
<Shortcut>mvvmcrossset</Shortcut>
<Author>Andrew Coates (based on Aboo's SO ReSharper Answer)</Author>
<HelpUrl>https://stackoverflow.com/questions/18200679/MvvmCross-code-snippets-for-visual-studio</HelpUrl>
</Header>
<Snippet>
<Declarations>
<Literal>
<ID>viewName</ID>
<ToolTip></ToolTip>
<Default>viewName</Default>
</Literal>
<Literal>
<ID>element</ID>
<ToolTip></ToolTip>
<Default>element</Default>
</Literal>
</Declarations>
<Code Language="CSharp">
<![CDATA[var set = this.CreateBindingSet<$viewName$View, $viewName$ViewModel>();
set.Bind($element$).To(vm => vm$end$);
set.Apply();
]]>
</Code>
</Snippet>
</CodeSnippet>
</CodeSnippets>

Related

Dynamically add html elements to a Razor Page, Asp.Net Core

I would like to dynamically add elements to a Razor page in Asp.Net Core like this:
#using System
#{
string Greeting = $"Yo Dawg! {DateTime.Now.ToString()}";
string GreetingElement = $"<p id='second'>2nd: {Greeting}</p>";
}
<div>
#*I understand how to do this:*#
<p id="first">1st: #Greeting</p>
#*I cannot figure out how to do something like this:*#
#GreetingElement
</div>
The above results in this page source:
<p id="first">1st: Yo Dawg! 3/26/2020 9:22:05 AM</p>
<p id='second'>2nd: Yo Dawg! 3/26/2020 9:22:05 AM</p>
</div>
And I want to have this:
<p id="first">1st: Yo Dawg! 3/26/2020 9:22:05 AM</p>
<p id="second">2nd: Yo Dawg! 3/26/2020 9:22:05 AM</p>
</div>
You need to escape special characters, try changing this:
string GreetingElement = $"<p id='second'>2nd: {Greeting}</p>";
for this:
string GreetingElement = $"<p id='second'>2nd: {Greeting}</p>";
This might be useful: https://www.rapidtables.com/web/html/html-codes.html
I found that I can achieve this functionality with a partial view as follows:
test.cshtml:
#model album_tree_view_test.Pages.TestModel
<div>
<p id="first">1st: #Model.Greeting</p>
#{
await Html.RenderPartialAsync("_yo-dawg-partial");
// Model gets passed to partial view without referencing it.
}
</div>
test.cshtml.cs:
using Microsoft.AspNetCore.Mvc.RazorPages;
using System;
namespace album_tree_view_test.Pages
{
public class TestModel : PageModel
{
public string Greeting { get; set; }
public string Marker { get; set; }
public TestModel()
{
Greeting = $"Yo Dawg! {DateTime.Now.ToString()}";
Marker = "2nd";
}
public void OnGet()
{
}
}
}
_yo-dawg-partial.cshtml:
#model album_tree_view_test.Pages.TestModel
<p id="#Model.Marker">#Model.Marker: #Model.Greeting</p>
Generated Razor page source (excerpt):
<p id="first">1st: Yo Dawg! 3/26/2020 1:13:11 PM</p>
<p id="2nd">2nd: Yo Dawg! 3/26/2020 1:13:11 PM</p>
I can now use this functionally to generate nodes of tree view model recursively which was the original purpose of my question.

Unable to use <link> tag in Razor View

If I use the following code the view renders fine.
But if I change the url to the necessary RSS spec. the view will not render and throws an error saying that the tag is invalid so the error is occurring at the link tag. No matter what I try the link tag inside the razor foreach will not compile correctly.
#inherits Umbraco.Web.Mvc.UmbracoTemplatePage<ContentModels.RSsfeed>
#using ContentModels = Umbraco.Web.PublishedContentModels;
#{
Layout = null;
Response.ContentType = "text/xml";
var rootNode = Umbraco.TypedContentAtRoot().First();
var newsNodes = umbraco.uQuery.GetNodesByType("newsDetail");
}<?xml version="1.0"?>
<!-- News Aritcles -->
<rss version="2.0" xmlns:newsArticles="https://xxx.xxxxxxx.xxx/news">
<channel>
<title>News Aritcles</title>
<link>https://xxx.xxxxxxx.xxx/news</link>
<description>News Aritcles</description>
<language>en-us</language>
<ttl>1440</ttl>
#foreach(var newsNode in newsNodes){
var newsContent = UmbracoContext.Current.ContentCache.GetById(newsNode.Id);
string nnDescription = newsContent.GetPropertyValue("description").ToString();
string nnPublishDate = newsContent.GetPropertyValue("publishDate").ToString();
<item>
<title>#newsNode.Name</title>
<url>https://xxx.xxxxxxx.xxx#{#newsNode.Url}</url>
<description>#nnDescription</description>
<pubDate>#nnPublishDate</pubDate>
<guid>https://xxx.xxxxxxx.xxx#{#newsNode.Url}</guid>
</item>
}
</channel>
</rss>
<link/> is a void element, and so only has a start tag and no end tag - See W3C HTML Language Reference
You could output the tag like this
#("<link>" + newsNode.Url + "</link>")
Hope this helps

Admin-On-Rest add react-redux-toastr

i need to implement the extension "react-redux-toastr" into Admin-On-Rest.
how i can insert this code into the APP-Root
<ReduxToastr
timeOut={4000}
newestOnTop={false}
preventDuplicates
position="top-left"
transitionIn="fadeIn"
transitionOut="fadeOut"
progressBar/>
This is not working
<Admin customReducers={{ watchlistAdd: researchReducer, toastr: toastrReducer }} title="ProAmz" menu={Menu} restClient={jsonServerRestClient('http://dell.does-it.net:3306/api/v1')}>
<Resource name="amazon_products" title="Produkte" list={ProductList}/>
<Resource name="Watchlist" title="Watchlist" list={Watchlist} />
<div>
<ReduxToastr
timeOut={4000}
newestOnTop={false}
preventDuplicates
position="top-left"
transitionIn="fadeIn"
transitionOut="fadeOut"
progressBar/>
</div>
</Admin>
i won't use the "custom-app" https://marmelab.com/admin-on-rest/CustomApp.html version.

Why does the <c:if> statement doesn't execute in the jsp? [duplicate]

This question already has answers here:
Can not find the tag library descriptor for “http://java.sun.com/jsp/jstl/core” [duplicate]
(18 answers)
Closed 7 years ago.
This is a Spring Web MVC project where I do input validation in server side. If there are any errors, then I add it to the model before sending it to the view.
Controller
#Controller("resultController")
public class ResultController {
private final ResultService resultService;
#Autowired
public ResultController(ResultService resultService) {
this.resultService = resultService;
}
// #RequestMapping(value = "/search", method = RequestMethod.GET)
#RequestMapping(value ="/template", method = RequestMethod.GET)
public String getPersonList(ModelMap model) {
System.out.println("We are coming into this place");
return "header";
}
#RequestMapping(value = "/number", method = RequestMethod.POST, params = { "regNo" })
public String getStudentResult(#RequestParam(value = "regNo", required = true) String regNo, ModelMap model){
//Server side validation
if(regNo.equals(null) || regNo.isEmpty()){
model.addAttribute("nullValue", "Register Number field cannot be empty");
return "header";
}else if(regNo.length() != 12 ){
System.out.println("This Sys out is shown");
model.addAttribute("invalidLength", new String("invalid"));
return "header";
}else{
model.addAttribute("studentResult",resultService.getStudentResult(regNo));
return "numberResult";
}
}
}
header.jsp
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<head>
<script src="http://code.jquery.com/jquery.min.js"></script>
<style>
#mycontainer, h1, h3 {
text-align:center;
}
form {
display:inline-block;
}
/* #regNoErrorMsgNumber {
display: none;
background: brown;
color: white;
} */
</style>
</head>
<body>
<div id="mycontainer">
<form method="post" action="number" id="number">
<!-- <div id="regNoErrorMsgNumber">Only numbers are allowed</div> -->
<div style="text-align: center;" >
<!-- //TODO: Only number, no spaces, no special symbol and 12 digit check-->
<input width="20" type="text" data-validation="numbers" id="regNo" name="regNo" size="30" maxLength="50" placeholder="Enter Register Number"> <b>OR</b>
<div>
<c:if test="${not empty nullValue}">
<c:out value="${nullValue}"/>
</c:if>
<c:if test="${not empty invalidLength}">
<c:out value="Register Number should be 12 digits"/>
</c:if>
</div>
</div>
</form>
<form method="post" action="name" id="name">
<input type="text" id="studentName" name="studentName" size="30" maxLength="50" placeholder="Enter Student Name"></input>
</form>
</div>
<div style="text-align: center;">
<input id="inputFields" type="button" value="Search" />
</div>
<!-- </form> -->
<script>
$(document).ready(function(){
$('#inputFields').click(function(event){
if (document.getElementById('regNo').value !=""){
$("#number").submit();
}else if(document.getElementById('studentName').value !=""){
$("#name").submit();
}
});
});
</script>
</body>
The following piece of jstl code in jsp doesn't work
<c:if test="${not empty invalidLength}">
<c:out value="Register Number should be 12 digits"/>
</c:if>
Also if I use the c:out statement without c:if tag, then it works. But it misaligns two input fields in UI. You can see the div mycontainer code in jsp. I want the error message to be shown below the regNo input field, but at the same time regNo and studetnName input field should be center aligned in a single line.
PS: I get Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core". Try increasing the version of the Dynamic Web Module project facet, as this method of reference may not be supported by the current JSP version (1.1)., but c:out tag with being wrapped with c:if works.
please try the following :
if you are using maven , add this to your dependencies and maven will add the jar for you :
<dependencies>
<dependency>
<groupId>jstl</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
</dependencies>
if you are not using maven add the jstl library to your project (jstl-1.2.jar)
make sure you set a Targeted Runtime for your project , Tomcat , Glassfish , etc ...
and please refer to this question here .
for the errors part , use the <form:errors> from spring form tags :
- first add the following to your page :
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
then use the form:errors like the following :
<form:errors path="userName" cssClass="error" element="div" />
please refer to the following tutorials , here and here .
Hope that helps
I created a new class called ProjectErrors and I changed the code as follows
if(regNo.equals(null) || regNo.isEmpty()){
univErrors.setHasError(true);
model.addAttribute("isNull", univErrors );
}else if(Pattern.matches("[a-zA-Z]+", regNo)){
univErrors.setHasError(true);
model.addAttribute("onlyNumbers", univErrors );
}else if(regNo.length() != 12 ){
univErrors.setHasError(true);
model.addAttribute("length", univErrors );
}
I changed the jsp like this
<c:if test="${length.hasError}">
<c:out value="Register Number should be 12 digits."/>
</c:if>
<c:if test="${onlyNumbers.hasError}">
<c:out value="Register number can contain only digits."/>
</c:if>
And my error class looks like this
public class ProjectErrors {
public Boolean hasError;
public ProjectErrors(boolean b) {
// TODO Auto-generated constructor stub
hasError = b;
}
public Boolean getHasError() {
return hasError;
}
public void setHasError(Boolean hasError) {
this.hasError = hasError;
}
}
Now I see c:if tag working.
But, still get the warning in jsp "Can not find the tag library descriptor for "http://java.sun.com/jsp/jstl/core". Try increasing the version of the Dynamic Web Module project facet, as this method of reference may not be supported by the current JSP version (1.1).",

Get prefix of XML namespace from URI

How can I get the prefix of a xml namespace from URI?
example:
<Name xmlns:tiger="http://www.census.gov">
</Name>
I've got the
"http://www.census.gov"
I want to get the prefix
tiger
How can I do this in Actionscript / Flex?
thx
EDIT
The answer doesn't work with this complex example:
<Name xmlns:tiger="http://www.census.gov" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:it.geosolutions="http://www.geo-solutions.it" xmlns:cite="http://www.opengeospatial.net/cite" xmlns:worldWS="worldWS" xmlns:sde="http://geoserver.sf.net" xmlns:topp="http://www.openplans.org/topp" xmlns:sf="http://www.openplans.org/spearfish" xmlns:nurc="http://www.nurc.nato.int" xmlns:solWS="solWS">
tiger:poly_landmarks
</Name>
I've got empty Array.
ANSWER MY OWN Q
for EDIT example
var xml:XML = <Name xmlns:tiger="http://www.census.gov" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:it.geosolutions="http://www.geo-solutions.it" xmlns:cite="http://www.opengeospatial.net/cite" xmlns:worldWS="worldWS" xmlns:sde="http://geoserver.sf.net" xmlns:topp="http://www.openplans.org/topp" xmlns:sf="http://www.openplans.org/spearfish" xmlns:nurc="http://www.nurc.nato.int" xmlns:solWS="solWS">
tiger:poly_landmarks
</Name>
var ns:Namespace = xml.namespace("http://www.census.gov");
if(ns.uri == "http://www.census.gov")
....
var xml:XML = <Name xmlns:tiger="http://www.census.gov"></Name>;
var ns:Array = xml.namespaceDeclarations();
trace(ns[0].prefix); //output: tiger
UPD for complex xml (output tiger as well):
var xml:XML = <Name xmlns:tiger="http://www.census.gov" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:ows="http://www.opengis.net/ows" xmlns:gml="http://www.opengis.net/gml" xmlns:ogc="http://www.opengis.net/ogc" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:it.geosolutions="http://www.geo-solutions.it" xmlns:cite="http://www.opengeospatial.net/cite" xmlns:worldWS="worldWS" xmlns:sde="http://geoserver.sf.net" xmlns:topp="http://www.openplans.org/topp" xmlns:sf="http://www.openplans.org/spearfish" xmlns:nurc="http://www.nurc.nato.int" xmlns:solWS="solWS">
tiger:poly_landmarks
</Name>
var nss:Array = xml.namespaceDeclarations();
for each(var ns:Namespace in nss)
{
if(ns.uri == "http://www.census.gov")
{
trace(ns.prefix);
break;
}
}