self hosted vnext application - self-hosting

I was wondering if I could refactor a self-hosted app (console app that starts and displays the URL of the webservices it provides) for it to work on pure vnext instead of owin.
The owin code is the following
namespace Selfhostingtest
{
class Program
{
static void Main(string[] args)
{
String strHostName = string.Empty;
strHostName = Dns.GetHostName();
Console.WriteLine("Local Machine's Host Name: " + strHostName);
var options = new StartOptions();
IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
IPAddress[] addr = ipEntry.AddressList;
for (int i = 0; i < addr.Length; i++)
{
if (!addr[i].IsIPv6LinkLocal && addr[i].AddressFamily == AddressFamily.InterNetwork)
{
Console.WriteLine("IPv4 Address {0}: {1} ", i, addr[i].ToString());
options.Urls.Add(String.Format("http://{0}:5000/", addr[i].ToString()));
}
}
using (WebApp.Start<Startup>(options))
{
Console.WriteLine("Razor server is running. Press enter to shut down...");
Console.ReadLine();
}
}
}
}
For the record, I don't want to use the "k web" command line start. I want to fully package the vnext app as an executable file.
Instead of Microsoft.Owin.Hosting, the Microsoft.AspNet.Hosting should be used (same class as in the "k web" command definition. Keep in mind that Owin Startup expects IAppBuilder and the vnext expects IBuilder.

In ASP.NET vNext you cannot build an EXE file, but you can definitely package up an app to be self-contained. Check out the kpm pack command that you can run in your app's folder. It will package up all the dependencies as well as generate the command scripts that you can use (instead of using k web etc.). Ultimately if you look at what k web does, it's just some shell scripts that end up running klr.exe with various parameters to indicate what it should start.
The project wiki has some basic information on the kpm tool's various options: https://github.com/aspnet/Home/wiki/Package-Manager
Here is the command line help for kpm pack to give you an idea of what it can do.
Usage: kpm pack [arguments] [options]
Arguments:
[project] Path to project, default is current directory
Options:
-o|--out <PATH> Where does it go
--configuration <CONFIGURATION> The configuration to use for deployment
--overwrite Remove existing files in target folders
--no-source Don't include sources of project dependencies
--runtime <KRE> Names or paths to KRE files to include
--appfolder <NAME> Determine the name of the application primary folder
-?|-h|--help Show help information

Related

Websphere Console 9.0 - where to specify Application specific files paths in websphere console

Websphere version 9.0 is installed in our RHEL 8.3 OS .
Now in that i have deployed one web app - .war file which contains multiple modules - webservice, web module etc.
This war is successfully deployed and i am able to start it also going to Websphere Enterprise Applications - AppName - START.
The app gets started with a success message.
Now the problem lies ahead. Our application requires a certain file bootstrap.properties.
This file has several configurations like jdbc params, jmx ports, jms configurations, jvm arguments, logging paths etc.
Once the web module of this app is run on <SERVER_IP>:9080/Context url, it throws error on GUI saying Unable to locate bootstrap.properties.
Analysing at the code level , found out that below code is throwing this error:
private static Properties config;
private static final String CONFIG_ROOT = System.getProperty("bootstrap.system.propertiespath");
private static final String configFile = "bootstrap.properties";
private JMXConfig() {
}
public static String getConfigRoot() {
if (CONFIG_ROOT == null) {
System.err.println("Not able to locate bootstrap.properties. Please configure bootstrap.system.propertiespath property.");
throw new ConfigException("Unable to locate bootstrap.properties.");
} else {
return CONFIG_ROOT + File.separator;
}
}
I wanted to know where can we specify the absolute paths in the websphere console where our property file can be read as a system argument once the application is loaded.
Since you're using System.getProperty() to read the property, it needs to be specified as a Java system property passed into the JVM. You can do that from the JVM config panel, adding it as either a custom property on the JVM or as a -D option in the server's generic JVM arguments.
Custom property: https://www.ibm.com/docs/en/was/9.0.5?topic=jvm-java-virtual-machine-custom-properties
Generic JVM argument: https://www.ibm.com/docs/en/was/9.0.5?topic=jvm-java-virtual-machine-settings (search for "Generic JVM arguments")
Note that if you use a custom property, you would simply set the "name" field to "bootstrap.system.propertiespath" and the "value" to the path you need; if you use a generic JVM argument, you'd add an argument with the structure "-Dbootstrap.system.propertiespath=/path/to/file".

looking to translate the page to another language. localization example of total js?.Does it translate the whole page/welcome message?

// Total.js translation file
// Created: 2014-12-18 10:32
// index.html
T80818744 : Titulok
T-52966915 : Ahoj svet!
T-1870230665 : Total.js je webový framework pre Node.js
// IMPORTANT: This line was created manually
message : Priame čítanie
Total.js can translate only phrases wrapped in #(TEXT TO LOCALIZE). First you need to define Total.js delegate onLocale which can set the language for each request:
F.onLocale = function(req) {
// req.query.*
// req.cookie('cookie_name');
// req.headers['*']
switch (req.query.langauge) {
case 'sk':
case 'cz':
case 'ru':
return req.query.langauge;
}
return 'en';
};
framework tries to find a resource file in the form /resources/YOURLANGUAGE.resource
if the file exists then the framework applies localization
otherwise the framework will use a default resource called: default.resource (if exists)
otherwise the framework use the phrases defined in views
How to create a resource file with localization?
I have prepared great utilites for localization, just install Total.js framework as a global library from NPM: $ sudo npm install -g total.js
$ cd yourapp
$ totaljs --translate
Total.js terminal app will create translate.resource file. Localize this file and copy it to /resources/YOURLANGUAGE.resource and restart app. That's all.
Example
Documentation

Powershell DSC Hangs

So here's my issue, I am trying to use PS Dsc to install some basic packages, but whenever I try and run my script it looks like it starts but never finishes. I try to pass the -Force parameter as recommended but it seems like it's just stacking operations and these processes just keep getting stuck.
Here is my script
Configuration WebServer {
# Import the module that contains the resources we're using.
Import-DscResource -ModuleName PsDesiredStateConfiguration
Node "localhost" {
Package InstallAspNetWebPages2
{
Ensure = "Present"
Path =
"C:\Users\jryter\Documents\WebServerInstalls\AspNetWebPages2Setup.exe"
Name = "Microsoft ASP.NET Web Pages 2 Runtime"
ProductID = "EA63C5C1-EBBC-477C-9CC7-41454DDFAFF2"
}
}
}
WebServer -OutputPath "C:\DscConfiguration"
Start-DscConfiguration -Wait -Force -verbose -Path "C:\DscConfiguration"
the current LCM state is it's performing a consistency check.
I tried following this link -->
https://powershell.org/forums/topic/stop-dsc-configuration-which-is-runningstuck/
but to no avail....
is there some base configuration that I missed to run this stuff properly? Has anyone had this issue?
DSC probably started the exe and it just sits there waiting for your input. You need to add arguments for silent install.
Package InstallAspNetWebPages2
{
Ensure = "Present"
Path = "path\file.exe"
Name = "Microsoft ASP.NET Web Pages 2 Runtime"
ProductID = "EA63C5C1-EBBC-477C-9CC7-41454DDFAFF2"
Arguments = "/silent" or "/quiet"
}
I don't know what's the proper argument for this exe

WebEssentials tslint custom rules

I have a tslint.json file in my solution directory and I'm trying to create a custom rule following the guidelines on https://www.npmjs.com/package/tslint
I have created a "nonImportsRule.ts", have copied the code from the link and have added "no-imports": true to my tslint.json file however the rule is not being picked up.
The guide says that a rulesDirectory needs to be specified, but I have no idea where this should be configured?
Also - is it possible to setup Web Essentials to break the build if tslint rules are violated?
I had a same kind of a problem. I wanted to use the TSLint extensions, tslint-microsoft-contrib and codelyzer, together with Web Analyzer. This did not work. The first step to figure out why was to make an adaptation in server.js which can be found in C:\Users\[User]\AppData\Local\Temp\WebAnalyzer1.7.75. I changed the TSLint function into:
tslint: function (configFile, files) {
// Try catch tslint errors
try {
var tslint = require("tslint");
var options = {
formatter: "json",
configuration: JSON.parse(fs.readFileSync(configFile, "utf8").trim())
};
var results = [];
for (var i = 0; i < files.length; i++) {
var file = files[i];
var ll = new tslint(file, fs.readFileSync(file, "utf8"), options);
results = results.concat(JSON.parse(ll.lint().output));
}
} catch(error) {
// Return tslint error to visual studio so we can get some ideas for counter measures.
var result = JSON.parse('[{"endPosition": {"character": 0,"line": 0,"position": 0},"failure": "INSTALL ERROR","name": "/","ruleName": "INSTALL ERROR","startPosition": {"character": 0,"line": 0,"position": 0}}]');
result[0].failure = error.message;
return result;
}
return results;
},
The alternation resulted in error feedback in the visual studio error list when I run the Web Analyzer. Do not forget to force a new instance of node.exe with the task manager after you have applied the alternation. The feedback leaded, for my particular situation, to the following installation of npm packages in the following directories:
Packages:
"codelyzer": "0.0.12"
"tslint": "^3.7.3"
"tslint-microsoft-contrib": "^2.0.2"
"typescript": "^1.8.9"
Directories:
C:\Users\[User]\AppData\Local\Temp\WebAnalyzer1.7.75
C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
After this, Web Analyzer was able to use the same tslint rules as my grunt task. Hopefully a newer version of Web Analyzer will solve my problems more elegantly.
Okay, i'm not using Web Essentials extension but Web Analyzer : https://visualstudiogallery.msdn.microsoft.com/6edc26d4-47d8-4987-82ee-7c820d79be1d
So i won't be able to answer on this question 100%, but i want to summarize here my experience with custom tslint rules. First of all, what is not completely clear from documentation is that the whole thing depends on node.js.
So first of all you need to install node js. This will give you npm command to your command line.
After install with npm tslint and typescript. https://github.com/palantir/tslint here are examples. These will create files in : "c:\Users[Username]\AppData\Roaming\npm\node_modules"
Go into "c:\Users[Username]\AppData\Roaming\npm\node_modules\tslint\lib\rules\". Create here noImportRule.ts. Copy the following content:
import * as ts from "typescript";
import * as Lint from "../lint";
export class Rule extends Lint.Rules.AbstractRule {
public static FAILURE_STRING = "import statement forbidden EDE";
public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] {
return this.applyWithWalker(new NoImportsWalker(sourceFile, this.getOptions()));
}
}
// The walker takes care of all the work.
class NoImportsWalker extends Lint.RuleWalker {
public visitImportDeclaration(node: ts.ImportDeclaration) {
// create a failure at the current position
this.addFailure(this.createFailure(node.getStart(), node.getWidth(), Rule.FAILURE_STRING));
// call the base version of this visitor to actually parse this node
super.visitImportDeclaration(node);
}
}
Note that in the example import lint is not given with relative path that won't work with this approach.
4. Fire the command : "tsc -m commonjs --noImplicitAny .\noImportsRule.ts". This will compile your custom rule's ts. You will get bunch of compilation errors, such as: ../enableDisableRules.d.ts(1,21): error TS2307: Cannot find module 'typescript'. That's a good question why are these thrown, but forget about them, js file will be generated anyway.
5. Put "no-imports": true to your tslint.json(for now this should be custom one). With this command from command line:
tslint -c 'sample.tslint.json' test.ts
you will get:
test.ts[1, 1]: import statement forbidden. So you made the custom rule working!!! :)
That's all for working from command line. In addition I made custom rules working with WebAnalyzer, at least temporary.
I needed to copy my custom rule's files here:
c:\Users[Username]\AppData\Local\Temp\WebAnalyzer1.6.65\node_modules\tslint\lib\rules\ and of course configure WebAnalyzer tslint.json to include custom rules.
I have no idea how Web Essentials extension makes this whole thing working with tslint, but i guess some way similar :). Somewhere there should be a folder (node_modules\tslint\lib\rules) with rules what tslint uses. There you need to copy your custom ones.
Of course the most elegant solution would be to modify Web Essentials extension itself and make the tslint's custom rules directory configurable from visual studio. (so my solution is just a workaround)
Here is my custom rule example in the visual studio warning's list:

How do we manually fix "ResourceRules.plist: cannot read resources" error after xcode 6.1 upgrade?

We are having the same issue found here, here, here and here
Basically we upgraded to xcode 6.1 and our build are getting the "ResourceRules.plist: cannot read resources" error.
We have a Jenkins server that does our ios builds for us. We are using the Xcode plugin on Jenkins to do the actual build and signing. Any thoughts on how we can make this change without manually opening xcode and doing this solution found on the other answers:
Click on your project > Targets > Select your target > Build Settings >
Code Signing Resource Rules Path
and add :
$(SDKROOT)/ResourceRules.plist
I'm very new to Xcode and iOS build in general. I have found the project.pbxproj file inside the Unity-iPhone.xcodeproj file. It looks like this contains the build settings under the /* Begin XCBuildConfiguration section */ section it lists what looks like similar build properties foundin Xcode, however I do not see anything like "Code Signing Resource Rules Path".
Does anyone have experience manually editing this file? Is that a bad idea in general?
Thanks
If you're using Jenkins with the XCode plugin, you can modify the 'Code Signing Resource Rules Path' variable by adding:
"CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plist"
to the
'Custom xcodebuild arguments' setting for the XCode plugin.
This fix does not require the XCode GUI.
I encountered the same problem. Nicks solution does work, but is requiring additional dependencies. You don't need the heavy-handed npm xcode module for this. Just add a line to this file:
$PROJECT_ROOT/platforms/ios/cordova/build.xcconfig
CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plist
Note that before XCode 6.1.1, this needed to be specified as "$(SDKROOT)/ResourceRules.plist" (notice the quotes).
If you are running this inside automated build systems such as Jenkins and wont't/can't use any XCode GUI, just create a small Cordova hook, leveraging npm's fs.appendFile, at this location:
$PROJECT_ROOT/hooks/before_build/ios_resourcerules.js (make sure it has chmod +x)
#! /usr/local/bin/node
var fs = require("fs");
fs.appendFileSync('build.xcconfig', '\nCODE_SIGN_RESOURCE_RULES_PATH = $(SDKROOT)/ResourceRules.plist', function (err) {
if (err) throw err;
console.log('CODE_SIGN_RESOURCE_RULES_PATH added to Cordova iOS build configuration.');
});
This will might be merged in an upcoming Cordova release, so the hook will become unnecessary (i'm creating a see this PR for Cordova-iOS).
In case the above JavaScript snippet fails to execute due to a "wrong argument" failure, replace the file's content as follows:
#!/bin/bash
if [ ! -f ./build.xcconfig ]; then
echo "[ERROR] hook befor_build/ios_resourcerules.sh cannot execute, ./build/xcconfig not found in $PWD"
exit 1
fi
echo '// (CB-7872) Solution for XCode 6.1 signing errors related to resource envelope format deprecation' >> ./build.xcconfig
echo 'CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plist' >> ./build.xcconfig
echo 'CODE_SIGN_RESOURCE_RULES_PATH added to Cordova iOS build configuration.'
If you want to get really crazy, you can directly update PackageApplication.
# In /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/PackageApplication
my #codesign_args = ("/usr/bin/codesign", "--force", "--preserve-metadata=identifier,entitlements,resource-rules",
"--sign", $opt{sign},
"--resource-rules=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/ResourceRules.plist");
# OLD: "--resource-rules=$destApp/ResourceRules.plist");
I was already hacking this script to accept a keychain arg, so it made sense for me. Note I'm not using the Xcode Jenkins plugin -- I'm using Jenkins but running all the build commands from a script.
After the new release of XCode 7 on 23rd Sept 2015, Apple started rejecting any application that is using CODE_SIGN_RESOURCE_RULES_PATH, making the Jenkins build automatically rejected. However, setting CODE_SIGN_RESOURCE_RULES_PATH=$(SDKROOT)/ResourceRules.plist into the Custom xcodebuild arguments causes a build failure.
This answer resolved the issue: https://stackoverflow.com/a/32762413/5373468
This is clearly a bug that Apple forgot to fix a while ago, as this article is also highlighting: http://cutting.io/posts/packaging-ios-apps-from-the-command-line/
I had EXACTLY the same problem, as you have. We are building our iOS app on Jenkins, so we couldn't manually set "Code Signing Resource Rules Path".
I have wrote a small NodeJS file which does the job for me (see the code below).
The script use a nice NodeJS package called xcode which helps me with the parsing of the xcode.xcodeproj file.
I don't know if you are using Cordova/Phonegap or what you are using, but if you are can just copy the code and make a Cordova hook. If not I'm sure you can execute the file from Jenkins, with some small changes.
Anyways, I hope this script will help you:
#!/usr/bin/env node
var CODE_SIGN_RESOURCE_RULES_PATH = '"$(SDKROOT)/ResourceRules.plist"';
var fs = require("fs");
var path = require("path");
var xcode = require('xcode');
var projectRoot = process.argv[2];
function getProjectName(protoPath) {
var cordovaConfigPath = path.join(protoPath, 'www', 'config.xml');
var content = fs.readFileSync(cordovaConfigPath, 'utf-8');
return /<name>([\s\S]*)<\/name>/mi.exec(content)[1].trim();
}
function run(projectRoot) {
var projectName = getProjectName(projectRoot);
var xcodeProjectName = projectName + '.xcodeproj';
var xcodeProjectPath = path.join(projectRoot, 'platforms', 'ios', xcodeProjectName, 'project.pbxproj');
var xcodeProject;
if (!fs.existsSync(xcodeProjectPath)) {
return;
}
xcodeProject = xcode.project(xcodeProjectPath);
console.log('Setting Code Sign Resource Rules Path for ' + projectName + ' to: [' + CODE_SIGN_RESOURCE_RULES_PATH + '] ...');
xcodeProject.parse(function(error){
if(error){
console.log('An error occured during parsing of [' + xcodeProjectPath + ']: ' + JSON.stringify(error));
}else{
var configurations = nonComments(xcodeProject.pbxXCBuildConfigurationSection());
for (config in configurations) {
var buildSettings = configurations[config].buildSettings;
buildSettings['CODE_SIGN_RESOURCE_RULES_PATH'] = CODE_SIGN_RESOURCE_RULES_PATH;
}
fs.writeFileSync(xcodeProjectPath, xcodeProject.writeSync(), 'utf-8');
console.log('[' + xcodeProjectPath + '] now has Code Signing Resource Rules Path set to:[' + CODE_SIGN_RESOURCE_RULES_PATH + '] ...');
}
});
}
var COMMENT_KEY = /_comment$/;
function nonComments(obj) {
var keys = Object.keys(obj),
newObj = {}, i = 0;
for (i; i < keys.length; i++) {
if (!COMMENT_KEY.test(keys[i])) {
newObj[keys[i]] = obj[keys[i]];
}
}
return newObj;
}
run(projectRoot);
We are using Unity + Jenkins for auto builds.
You can achieve with post process cs scripts; however; for quick (and dirty fix) you can apply following bash command after Unity but before xcode:
sed -i '' 's/CONFIGURATION_BUILD_DIR/CODE_SIGN_RESOURCE_RULES_PATH = "\$(SDKROOT)\/ResourceRules\.plist";\'$'\n CONFIGURATION_BUILD_DIR/g' /Users/admin/Jenkins/workspace/PROJECTNAME/Build/PROJECTNAME/Unity-iPhone.xcodeproj/project.pbxproj

Resources