MVC4 WebApplication - global variables available in views (cshtml files) using Razor engine - internationalization

I wonder how it is now possible, using MVC4, to get such functionality which was possible in MVC3, to declare some variables (and/or constraints) which are then available in all cshtml files. I used this to make language files.
Earlier (in MVC3) I had App_Code folder in my Solution, where I put the file Lang.cshtml. In this file (valid resource for me) I had e.g.
#functions{
public static readonly string G_ADD = "Dodaj";
public static readonly string G_CREATE = "Utwórz";
public static readonly string G_SAVE = "Zapisz";
public static readonly string G_EDIT = "Edytuj";
public static readonly string G_DETAILS = "Szczegóły";
public static readonly string G_DELETE = "Usuń";
public static readonly string G_SEARCH = "Szukaj";
public static readonly string G_FIRST = "<< Pierwsza";
public static readonly string G_LAST = "Ostatnia >>";
public static readonly string G_PREV = "< Poprzednia";
public static readonly string G_NEXT = "Następna >";
public static readonly string G_ACTION = "Akcja";
public static readonly string G_ID = "ID";
public static readonly string G_PAGE = "STRONA";
public static readonly string G_OF = "z";
public static readonly string G_FROM = "z";
public static readonly string G_TO = "do";
public static readonly string G_ALL = "-- Wszystkie";
public static readonly string G_RECORDS = "Rekordów:";
public static readonly string G_CHOOSE = "Wybierz:";
public static readonly string G_BACK = "Wróć";
public static readonly string G_VIEW_CHART = "Wyświetl wykres";
}
so I could use the strings in any .cshtml (View) e.g.
#Lang.G_ADD
or even
#Html.ActionLink(#Lang.G_ADD, "AddContract", new { id = item.CONTRACT_ID });
Especially it makes my app more user-friendly for all those people working on i18n of it.
Now this solution doesn't work in MVC4 :/
The available resources solution is not much-effective. Imagine, that everytime you need to write AppName.Properties.Resources.G_ADD.
Also the XML in the Resources.resx looks baaaaaaadly. Very.
Writting any method to enumerate the Resources still do the job partially only as it is bloating the code and I am following "less the code the better" idea.
Please point me to the right direction. Also any ready solution is appreciated :)
Thank You all in advance!

Related

java.lang.IllegalArgumentException: column '`kitType`' does not exist. Available columns: [..., dependencies, ൔ, DMLoader, ...]

I get an expcetion when I try query some data from db.(RoomDb Version used:2.2.5)
It never reproduced in DEV. It only happened in PRD sometime on API 27 28 29 30.
Crash scenes:
1. Some time columnName of my database was changed to garbled.
java.lang.IllegalArgumentException: column 'kitType' does not exist. Available columns: [kitName, apiLevel, pkgVersionCode, packageName, kitCodePath, moduleCodePath, soLibraryPath, dependencies, ൔ, DMLoader, archType, forceUpgrade, ignoreForceUpgradeTime, mainEntry, kitState, moduleState, usesLibraryPath, appClass, reservedString1, reservedString2, reservedInt1, reservedInt2, reservedInt3]
as show above:kitType was changed to ൔ.
2. Some time columnName of my database was changed to other columnName.
java.lang.IllegalArgumentException: column 'reservedInt2' does not exist. Available columns: [id, packageName, pkgVersionCode, classname, actions, categories, intentFilter, reservedString1, reservedString2, reservedInt1, reservedInp2, reservedInt3, packageState]
as show above: reservedInt2 was changed to reservedInp2.
This is my Entity code:
#Entity(tableName = PackageInfoEntity.PACKAGE_INFO_TABLE_NAME,
primaryKeys = {PackageInfoEntity.PACKAGE_NAME, PackageInfoEntity.PKG_VERSION_CODE})
public class PackageInfoEntity {
#Ignore
public static final String PACKAGE_INFO_TABLE_NAME = "PackageInfoTable";
#Ignore
public static final String PACKAGE_NAME = "packageName";
#Ignore
public static final String PKG_VERSION_CODE = "pkgVersionCode";
#Ignore
public static final String APPLICATION_INFO = "applicationInfo";
#Ignore
public static final String PACKAGE_INFO = "packageInfo";
#Ignore
public static final String REF_COUNT = "refCount";
#Ignore
public static final String LAST_MODIFY = "lastModify";
#Ignore
public static final String PACKAGE_STATE = "packageState";
#Ignore
public static final String MODULE_PKG_STATE = "modulePkgState";
#Ignore
public static final String INVALID_TIME = "invalidTime";
#Ignore
public static final String PRE_PKG_NAME = "prePkgNames";
#Ignore
public static final String FUTURE_PKG_NAME = "futurePkgName";
#Ignore
private static final String TAG = "PackageInfoEntity";
#Ignore
public static final String RESERVEDSTRING_01 = "reservedString1";
#Ignore
public static final String RESERVEDSTRING_02 = "reservedString2";
#Ignore
public static final String RESERVEDINT_01 = "reservedInt1";
#Ignore
public static final String RESERVEDINT_02 = "reservedInt2";
#Ignore
public static final String RESERVEDINT_03 = "reservedInt3";
#NonNull
public String packageName;
#NonNull
public int pkgVersionCode;
#NonNull
#ColumnInfo(typeAffinity = ColumnInfo.BLOB)
public ApplicationInfo applicationInfo;
#NonNull
#ColumnInfo(typeAffinity = ColumnInfo.BLOB)
public PackageInfo packageInfo;
public int packageState;
public int modulePkgState;
public long invalidTime;
public String prePkgNames;
public String futurePkgName;
public String reservedString1;
public String reservedString2;
public Integer reservedInt1;
public Integer reservedInt2;
public Integer reservedInt3;
}
What I have tried:
This error never happened on my In-progress version with same app version.
I want to try add a try/catch block,but this database query is located on so many functions.
So is any advice can I figure this out.

Hapi Fhir Constants for "Common Parameters defined for all resources"

http://www.hl7.org/implement/standards/fhir/search.html#advanced
Common Parameters defined for all resources:
Name Type Description Paths
_id token Resource id (not a full URL) Resource.id
_lastUpdated date Date last updated. Server has discretion on the boundary precision Resource.meta.lastUpdated
_tag token Search by a resource tag Resource.meta.tag
_profile uri Search for all resources tagged with a profile Resource.meta.profile
_security token Search by a security label Resource.meta.security
_text string Text search against the narrative
_content string Text search against the entire resource
_list string All resources in nominated list (by id, not a full URL)
_query string Custom named query
Is there a Hapi Fhir "constant" somewhere for these?
Today I happen to be looking for "_profile".
I've check the SP_ values for
org.hl7.fhir.r4.model.DomainResource;
org.hl7.fhir.r4.model.ListResource;
org.hl7.fhir.r4.model.Resource
but no luck.
I found org.hl7.fhir.r4.model.Resource.SP_RES_ID (as "_id")
String SP_RES_ID = "_id";
But not for the other "standard" ones.
Thanks.
Gradle package reference:
implementation group: 'ca.uhn.hapi.fhir', name: 'hapi-fhir-structures-r4', version: hapiFhirVersion
hapiFhirVersion = '5.1.0'
I found some
https://hapifhir.io/hapi-fhir/apidocs/hapi-fhir-base/ca/uhn/fhir/rest/api/Constants.html#PARAM_PROFILE
Package ca.uhn.fhir.rest.api
Constants.PARAM_PROFILE
public static final String PARAM_PROFILE = "_profile";
and some others since you found this question!
/**
* Used in paging links
*/
public static final String PARAM_BUNDLETYPE = "_bundletype";
public static final String PARAM_FILTER = "_filter";
public static final String PARAM_CONTAINED = "_contained";
public static final String PARAM_CONTAINED_TYPE = "_containedType";
public static final String PARAM_CONTENT = "_content";
public static final String PARAM_COUNT = "_count";
public static final String PARAM_DELETE = "_delete";
public static final String PARAM_ELEMENTS = "_elements";
public static final String PARAM_ELEMENTS_EXCLUDE_MODIFIER = ":exclude";
public static final String PARAM_FORMAT = "_format";
public static final String PARAM_HAS = "_has";
public static final String PARAM_HISTORY = "_history";
public static final String PARAM_INCLUDE = "_include";
public static final String PARAM_INCLUDE_QUALIFIER_RECURSE = ":recurse";
public static final String PARAM_INCLUDE_RECURSE = "_include" + PARAM_INCLUDE_QUALIFIER_RECURSE;
public static final String PARAM_INCLUDE_QUALIFIER_ITERATE = ":iterate";
public static final String PARAM_INCLUDE_ITERATE = "_include" + PARAM_INCLUDE_QUALIFIER_ITERATE;
public static final String PARAM_LASTUPDATED = "_lastUpdated";
public static final String PARAM_NARRATIVE = "_narrative";
public static final String PARAM_PAGINGACTION = "_getpages";
public static final String PARAM_PAGINGOFFSET = "_getpagesoffset";
public static final String PARAM_PRETTY = "_pretty";
public static final String PARAM_PRETTY_VALUE_FALSE = "false";
public static final String PARAM_PRETTY_VALUE_TRUE = "true";
public static final String PARAM_PROFILE = "_profile";
public static final String PARAM_QUERY = "_query";
public static final String PARAM_RESPONSE_URL = "response-url"; //Used in messaging
public static final String PARAM_REVINCLUDE = "_revinclude";
public static final String PARAM_REVINCLUDE_RECURSE = PARAM_REVINCLUDE + PARAM_INCLUDE_QUALIFIER_RECURSE;
public static final String PARAM_REVINCLUDE_ITERATE = PARAM_REVINCLUDE + PARAM_INCLUDE_QUALIFIER_ITERATE;
public static final String PARAM_SEARCH = "_search";
public static final String PARAM_SECURITY = "_security";
public static final String PARAM_SINCE = "_since";
public static final String PARAM_SORT = "_sort";
public static final String PARAM_SORT_ASC = "_sort:asc";
public static final String PARAM_SORT_DESC = "_sort:desc";
public static final String PARAM_SOURCE = "_source";
public static final String PARAM_SUMMARY = "_summary";
public static final String PARAM_TAG = "_tag";
public static final String PARAM_TAGS = "_tags";
public static final String PARAM_TEXT = "_text";
public static final String PARAM_VALIDATE = "_validate";
public static final String PARAMQUALIFIER_MISSING = ":missing";
public static final String PARAMQUALIFIER_MISSING_FALSE = "false";
public static final String PARAMQUALIFIER_MISSING_TRUE = "true";
public static final String PARAMQUALIFIER_STRING_CONTAINS = ":contains";
public static final String PARAMQUALIFIER_STRING_EXACT = ":exact";
public static final String PARAMQUALIFIER_TOKEN_TEXT = ":text";

How to filter source file using gradle?

Is there any plugin or solution to filter source file. When i am using maven there is plugin https://github.com/wavesoftware/templating-maven-plugin
That plugin work like a charm is there any solution for gradle, to achieve the same result.
For example i am crate interface that holds all information about build:
public interface BuildConfig {
public static final String PROFILE_FAST = "fast";
public static final String PROFILE_DEV = "dev";
public static final String PROFILE_TEST = "test";
public static final String PROFILE_UAT = "uat";
public static final String PROFILE_PROD = "prod";
public static final String APP_CODE = "${app-code}";
public static final String PROFILE_ID = "${profile-id}";
public static final String APP_VERSION = "${project.version}";
public static final boolean DEBUG = !("${profile-id}").equals(PROFILE_PROD);
}
thanks

Why freemarker not reading my Java object (POJO)?

I am using freemarker to process html elements, inside the template file, it can read one of my legacy java object by giving ${form.fontStyle}, but it doesn't read my newly created java object"
public class SectionHeaderInfo implements Serializable {
private static final long serialVersionUID = 1L;
// the form object holds the setting of the form.
private Form form;
// the form section object
private FormSection section;
private String languageText;
public String name;
public SectionHeaderInfo(Form form, FormSection section, String languageText) {
this.form = form;
this.section = section;
this.languageText = languageText;
}
public void getName() {
return "whatever";
}
I added getName just for testing, but it complains
Caused by: freemarker.core.UnexpectedTypeException: For "." left-hand operand: Expected a hash, but this evaluated to a (wrapper: com.xxx.SectionHeaderInfo):
I compared the two java classes, tried implements TemplateModel, Serializable, nothing can get it work.
What am I missing here ?

AutoMapper mapping model list

I am trying to use AutoMapper for the first time and have some problems with it.
My code is below and I get error below. Maybe someone could show how to map the list of models?
cannot convert from 'System.Linq.IQueryable<AnonymousType#1>' to 'Entity.Product' C:\Users\Administrator\Projects\PC\trunk\PC\Controllers\AdminController.cs 37 100 PC
public class ProductViewModel
{
public int Id { get; set; }
public string Name { get; set; }
public int UsersCount { get; set; }
}
var products = _repository.GetProducts(true).Select(p=> new
{
p.Id,
p.Name,
UsersCount = 0
});
Mapper.CreateMap<Product, ProductViewModel>();
ViewData["Products"] = Mapper.Map<IEnumerable<Product>, IEnumerable<ProductViewModel>>(products); //Error appears on products object
//Product domain model(linq2sql generated model)
public partial class Product : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private int _Id;
private bool _Active;
private System.Nullable<int> _Sort;
private System.Nullable<int> _Category;
private string _Name;
private int _ProductTypeId;
private decimal _Price;
private System.Nullable<int> _Months;
private System.Nullable<int> _Credits;
private string _Features;
private string _BlockReason;
private string _BuyUrl1;
private string _BuyUrl2;
private bool _UsersManager;
}
In your LINQ query you select an anonymous object. Make sure you select a Product which is your source type (or more specifically IEnumerable<Product>):
IEnumerable<Product> products = _repository.GetProducts(true);
IEnumerable<ProductViewModel> productsViewModel = Mapper.Map<IEnumerable<Product>, IEnumerable<ProductViewModel>>(products);
return View(productsViewModel);
Also do not call Mapper.CreateMap<TSource, TDest> inside your controller action. This must be called only once in the lifetime of the AppDomain, ideally in your Application_Start.
Also notice that I have gotten rid of ViewData which is a great thing. You don't need ViewData. You are working with view models. That's what they are supposed to do. Contain information that will be needed by your view in a strongly typed manner.

Resources