MVC Scaffolding View using custom template - asp.net-mvc-scaffolding

I have created a custom template as follows:
Scaffold CustomTemplate View Index
As a result, I now have a local T4 template:
I made some modifications to the template. My question is how to generate code only for the view. I have done the following which works but which in my opinion is overkill since all I want is for my view to be generated.
Scaffold Controller -ModelType Task -ControllerName TasksController -DbContextType TasksDbContext -Repository -Force

I've managed to find out what command to pass:
Scaffold View -ModelType Task -Controller Tasks -ViewName Index -Template Index -Force
What I didn't know about was the -Template string switch.

Related

Substitute Service Fabric application parameters during deployment

I'm setting up my production environment and would like to secure my environment-related variables.
For the moment, every environment has its own application parameters file, which works well, but I don't want every dev in my team knowing the production connection strings and other sensitive stuffs that could appear in there.
So I'm looking for every possibility available.
I've seen that in Azure DevOps, which I'm using at the moment for my CI/CD, there is some possible variable substitution (xml transformation). Is it usable in a SF project?
I've seen in another project something similar through Octopus.
Are there any other tools that would help me manage my variables by environment safely (and easily)?
Can I do that with my KeyVault eventually?
Any recommendations?
Thanks
EDIT: an example of how I'd like to manage those values; this is a screenshot from octopus :
so something similar to this that separates and injects the values is what I'm looking for.
You can do XML transformation to the ApplicationParameter file to update the values in there before you deploy it.
The other option is use Powershell to update the application and pass the parameters as argument to the script.
The Start-ServiceFabricApplicationUpgrade command accept as parameter a hashtable with the parameters, technically, the builtin task in VSTS\DevOps transform the application parameters in a hashtable, the script would be something like this:
#Get the existing parameters
$app = Get-ServiceFabricApplication -ApplicationName "fabric:/AzureFilesVolumePlugin"
#Create a temp hashtable and populate with existing values
$parameters = #{ }
$app.ApplicationParameters | ForEach-Object { $parameters.Add($_.Name, $_.Value) }
#Replace the desired parameters
$parameters["test"] = "123test" #Here you would replace with your variable, like $env:username
#Upgrade the application
Start-ServiceFabricApplicationUpgrade -ApplicationName "fabric:/AzureFilesVolumePlugin" -ApplicationParameter $parameters -ApplicationTypeVersion "6.4.617.9590" -UnmonitoredAuto
Keep in mind that the existing VSTS Task also has other operations, like copy the package to SF and register the application version in the image store, you will need to replicate it. You can copy the full script from Deploy-FabricApplication.ps1 file in the service fabric project and replace it with your changes. The other approach is get the source for the VSTS Task here and add your changes.
If you are planning to use KeyVault, I would recommend the application access the values direct on KeyVault instead of passing it to SF, this way, you can change the values in KeyVault without redeploying the application. In the deployment, you would only pass the KeyVault credentials\configuration.

Liferay 6.2 Kaleo notification e-mail can't call operations of services

I'm developing a custom kaleo workflow with e-mail notifications. For notifications, I'm using Velocity and I would like to get some information from Liferay services. This is a small code sample that gives me problems:
#set ($resourceUtil = $serviceLocator.findService("com.liferay.portlet.journal.service.JournalArticleResourceLocalService"))
$resourceUtil
#set ($resourcePK = $getterUtil.getInteger($entryClassPK))
$resourcePK
#set ($resource = $resourceUtil.getJournalArticleResource($resourcePK))
$resource
If I use the previous code, the notification that I get is the following:
com.liferay.portlet.journal.service.impl.JournalArticleResourceLocalServiceImpl#3baa7cf0
6563724
$resource
As you can see, I get the correct JournalArticleResourceLocalService, I get the correct value for the resource PK, but when I call the operation to get the resource, I always get a null.
This is a sample with a resource but I've tried with some other lifeary services and I always get no response. This leads me to think that perhaps I've to enable some property or do something different to be able to call the service operations?
Any hiny will be appreciated. I'm using Liferay 6.2. The same code in Liferay 6.0 works fine...
Give a try with
com.liferay.portlet.journal.service.JournalArticleResourceLocalServiceUtil
instead of
com.liferay.portlet.journal.service.JournalArticleResourceLocalService
still, this is just my first advice looking just on code. If this won't solve your problem I will try test it later on my environment.

Kohana: Adapting Mixu's Auth Useradmin Template

I'm looking at Mixu's Auth module for Kohana 3.1 but want to implement the UI into my own site templates. At the moment my site runs properly using its own template until it gets to a restricted page. At that point it loads the useradmin module's template for logins. I'd like to just load the page components into my own template and navigation.
What is the best way to go about this please? I had imagined I would be able to arrest the flow at some point within my 'application' environment without editing the 'module' environment.
EDIT:
I'm a little further along now. I've created two Controller classes:
application/classes/controller/app.php
application/classes/controller/user.php
Each extends the module class and replaces the template reference. Eg:
<?php defined('SYSPATH') or die('No direct access allowed.');
class Controller_User extends Useradmin_Controller_User {
public $template = 'smarty:maintemplate';
}
I guess this is the right approach. I'm using Smarty Templates which is compounding the issues as I need to merge different templates. I'll keep plugging away and see how I go.
I don't know about the best way, but I had a similar situation.
In the end, I copied part of the code from the module that I needed, and rolled my own implementation of the module.
Btw. Smarty is ok, but Kostache (Mustache for Kohana) rocks. More flexible and you can use the same templates for php and javascript.

SharePoint 2010 - Performance (New-SPWeb $Url).ApplyWebTemplate("{GUID}#MyCustomTemplate")

I want to create new SPWebs with a Custom Template.
$web = New-SPWeb $Url
$web.ApplyWebTemplate("{GUID}#MyCustomTemplate")
My problem is now that the creation from one SPWeb with the Custom Template takes about 40 s on my VM. Is there a other and faster way to create SPWebs with a Custom Template?
Why not use -template parameter. For example,
New-SPWeb -url $url -template "{GUID}#MyCustomTemplate"
I did not have a custom template to use but this took 2 seconds on my system.
#LaPhi, you'll get an exception when your custom WebTemplate is not yet activated on your Site (Collection).
I, too, cannot get "New-SPWeb $Url -template "TemplateName" to provision with the Template. You'll likely need to wait until the site is provisioned.
My Solution:
First create the new Web:
$web = New-SPWeb $UrlFull
After this, apply the Web template
$web.ApplyWebTemplate("{GUID}#NameCustomTemplate")
The reason is, that the Custom Template is not global.
You have to use this syntax
New-SPWeb -url $url -template "MyCustomTemplateName#0"
You can find these values in Configuration tag of your webtemp_*.xml
<Configuration ID="0" Title="MyCustomTemplateName" ...

Sharepoint get User information

I have MOSS server and users authorization is going trough AD.
I want to programmaticaly get some current user information, like e-mail, phome number.
I made the following steps:
1) create dll with [assembly: AllowPartiallyTrustedCallers]
2) i have the class PhoneBookCL that inherits System.Web.UI.WebControls.WebParts.WebPart
and I try to override CreateChildControls() for testing;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.Office.Server;
using Microsoft.Office.Server.UserProfiles;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.Portal;
public class PhoneBookCL : WebPart
{
SPUser currentUser = null;
protected override void CreateChildControls()
{
try
{
SPWeb web = SPControl.GetContextWeb(Context);
currentUser = web.CurrentUser;
}
catch (Exception exp) { value = exp.Message; }
}
}
3) assigned strong name to dll, then add SafeControl to web.config:
4) dll -> to \Bin directory, added this WebPart to SP webparts collection,
added the webpart to the new Page.
Refreshing the page going to the exception: unexpected exception.
If I delete
"SPWeb web = SPControl.GetContextWeb(Context);
currentUser = web.CurrentUser;"
then all works great.
I can create Label and change its Text property and other things.
Also I tried to inherit from Microsoft.SharePoint.WebControls.WebPart, which actually inherit UI...WebPart, so the result is the same.
Maybe there is some security issue?
This problem occurs as you are deploying dll to bin. I assume your web.config has trust level as WSS_minimal . Minimal trust will not permit accessing object model.
Therefore , you have the following options:
Deploy the webpart using a wsp with custom code access security. This is slightly tedious.
Change the trust level in web.config to Full.
Deploy the dll to GAC.
From a best practices perspective, deploying the dll to bin with custom code access security will be the best option. But if you dont have security restrictions, you can look at deploying to GAC to keep things simpler.
Reference : http://msdn.microsoft.com/en-us/library/ee909485%28office.12%29.aspx
Regards,
Faiz

Resources