Code section
You can use EnableInterfaceInterceptors() when using assembly injection.
How do I enable interceptors when I register with a configuration file.
var config = new ConfigurationBuilder().AddXmlFile("AutoFac.config").Build();
var module = new ConfigurationModule(config);
var builder = new ContainerBuilder();
builder.RegisterModule(module);
var container = builder.Build();
configuration files
<autofac defaultAssembly="Test.Multilingual.IService">
<components name="0">
<type>Test.Multilingual.Service.TestMessage, Test.Multilingual.Service</type>
<services name="0" type="Test.Multilingual.IService.ITestMessage" />
<injectProperties>true</injectProperties>
<instanceScope>perlifetimescope</instanceScope>
</components>
<components name="1">
<type>Test.Multilingual.LanguageChoiceForm, Test.Multilingual</type>
<injectProperties>true</injectProperties>
</components>
<components name="2">
<type>Test.Multilingual.MainForm, Test.Multilingual</type>
<injectProperties>true</injectProperties>
</components>
<components name="3">
<type>Test.Multilingual.BaseForm, Test.Multilingual</type>
<injectProperties>true</injectProperties>
</components>
<components name="4">
<type>Test.Multilingual.PopForm, Test.Multilingual</type>
<injectProperties>true</injectProperties>
</components>
<components name="5">
<type>Test.Multilingual.Core.MultilingualInterceptor, Test.Multilingual.Core</type>
<injectProperties>true</injectProperties>
</components>
</autofac>
How do I enable interceptors?????
Autofac configuration does not support interceptors.
As noted in the documentation:
Before diving too deeply into JSON/XML configuration, be sure to readĀ ModulesĀ - this explains how to handle more complex scenarios than the basic JSON/XML component registration will allow. Configuration in JSON/XML is not a feature-for-feature replacement for programmatic configuration, so complex scenarios may require a combination of JSON/XML and modules.
Related
I am trying to add google maps support to my android app. As I create whole application layout in code, I would like to create also the map object in code. This is class that should handle OnMapReady callback function.
public class MapReader : Java.Lang.Object, IOnMapReadyCallback
{
private LayoutBuilder layoutBuilder;
public MapReader(LayoutBuilder lb)
{
layoutBuilder = lb;
}
public void OnMapReady(GoogleMap googleMap)
{
layoutBuilder.OnMapLoaded(googleMap);
}
}
This is critical part of code creating the layout.
MapView mapView=new MapView(context);
mapView.LayoutParameters = layoutParams;
linearLayout.AddView(mapView);
mapReader = new MapReader(this);
mapView.GetMapAsync(mapReader);
The problem is that I get no error/exception. The OnMapReady function is never called and the screen is just empty. What can be wrong or how can I get additional info about such a behavior? I tried to follow steps from this video. In output window I tried to find lines that could help:
Loaded assembly: /storage/emulated/0/Android/data/AlienChessAndroid.AlienChessAndroid/files/.__override__/Xamarin.GooglePlayServices.Base.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/AlienChessAndroid.AlienChessAndroid/files/.__override__/Xamarin.GooglePlayServices.Basement.dll [External]
Loaded assembly: /storage/emulated/0/Android/data/AlienChessAndroid.AlienChessAndroid/files/.__override__/Xamarin.GooglePlayServices.Maps.dll [External]
There are a few lines in output window that don't look good but the application runs.
AOT module 'Mono.Android.dll.so' not found: dlopen failed: library "/data/app/AlienChessAndroid.AlienChessAndroid-1/lib/arm/libaot-Mono.Android.dll.so" not found
AOT module '/storage/emulated/0/Android/data/AlienChessAndroid.AlienChessAndroid/files/.__override__/Xamarin.Android.Support.v4.dll.so' not found: dlopen failed: library "/data/app/AlienChessAndroid.AlienChessAndroid-1/lib/arm/libaot-Xamarin.Android.Support.v4.dll.so" not found
AOT module '/Users/builder/data/lanes/4009/3a62f1ea/source/monodroid/builds/install/mono-armv7/lib/mono/aot-cache/arm/Xamarin.Android.Support.v4.dll.so' not found: dlopen failed: library "/data/app/AlienChessAndroid.AlienChessAndroid-1/lib/arm/libaot-Xamarin.Android.Support.v4.dll.so" not found
This is my manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="AlienChessAndroid.AlienChessAndroid" android:versionCode="1" android:versionName="1.0" android:installLocation="preferExternal">
<uses-sdk android:minSdkVersion="22" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application android:label="Alien Chess" android:icon="#drawable/Alien" android:largeHeap="true">
<meta-data android:name="com.google.android.gms.version" android:value="2" />
<meta-data android:name="com.google.android.maps.v2.API_KEY" android:value="AIzaSyAmxxxxxxxxxxxxxxxxxxxxxxxxx" />
</application>
UPDATE:
I added checking for google services availability as is shown here and it returns ConnectionResult.Success.
GoogleApiAvailability gaa=GoogleApiAvailability.Instance;
int resultCode=gaa.IsGooglePlayServicesAvailable(context);
if (resultCode ==ConnectionResult.Success)
{
...
}
After reading this question I changed the line
<meta-data android:name="com.google.android.gms.version" android:value="2" />
for
<meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />
Nothing changed.
In you I would try to create LinearLayout and MapView inside your layout axml (if you can) to be sure that it's as it should be, getting the map when it's time to call the GetMapAsync using FindViewById<MapView> on it's resource id.
Setup of the map and the call of GetMapAsync should be done inside OnStart and OnResume.
After you created your IOnMapReadyCallback you could also try to add directly an event handler like this to see if it's called:
mapReader.MapReady += (sender, args) => { };
Try also your code both on a device with one of the latest Android version but also on a Android 5.x so you are sure that you haven't problem with requesting of permissions at runtime introduced with Android 6.0.
I think I'm missing something as I can't seem to figure out how to have it write to a log file in json format using NLog setup in configuration file. The straight rolling file works fine, but not the json. The json target only outputs the message (not in json).
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<targets async="true">
<target xsi:type="File" name="rollingFile" fileName="${basedir}/logs/${shortdate}.log" archiveFileName="${basedir}/logs/{shortdate}_Archive{###}.log" archiveAboveSize="1000000" archiveNumbering="Sequence" layout="${longdate} ${uppercase:${level}} ${callsite} ${message}" />
<target xsi:type="File"
name="rollingFileJson"
fileName="${basedir}/logs/${shortdate}.json"
archiveFileName="${basedir}/logs/{shortdate}_Archive{###}.json"
archiveAboveSize="1000000"
archiveNumbering="Sequence"
layout="${json-encode} ${message}">
</target>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="rollingFile" />
<logger name="*" minlevel="Trace" writeTo="rollingFileJson" />
</rules>
</nlog>
As of the release of NLog 4.0.0 it is possible to use a layout that renders events as structured JSON documents.
Example taken from NLog project site:
<target name="jsonFile" xsi:type="File" fileName="${logFileNamePrefix}.json">
<layout xsi:type="JsonLayout">
<attribute name="time" layout="${longdate}" />
<attribute name="level" layout="${level:upperCase=true}"/>
<attribute name="message" layout="${message}" />
</layout>
</target>
Edit:
You can also create it in code.
Here is the link to the specific part of documentation.
And here the copied example:
var jsonLayout = new JsonLayout
{
Attributes =
{
new JsonAttribute("type", "${exception:format=Type}"),
new JsonAttribute("message", "${exception:format=Message}"),
new JsonAttribute("innerException", new JsonLayout
{
Attributes =
{
new JsonAttribute("type", "${exception:format=:innerFormat=Type:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}"),
new JsonAttribute("message", "${exception:format=:innerFormat=Message:MaxInnerExceptionLevel=1:InnerExceptionSeparator=}"),
}
},
//don't escape layout
false)
}
};
For more info read the docs.
As per NLog documentation: json-encode will only escape output of another layout using JSON rules. It will not "convert" the output to JSON. You'll have to do that yourself.
'{ "date":"${longdate}","level":"${level}","message":${message}}'
Take a look at this question for more details.
I am getting the following error while try to publish artifact into the remote repository.
BUILD FAILED
/home/kannan/.jenkins/workspace/projectA/build.xml:87: impossible to publish artifacts for com.mycompany#projectA;1.0: java.io.IOException: PUT operation to URL http://myserver.com/repository/com.mycompany/projectA/1.0/ivy-1.0.xml failed with status code 405: Method Not Allowed
at org.apache.ivy.util.url.AbstractURLHandler.validatePutStatusCode(AbstractURLHandler.java:82)
at org.apache.ivy.util.url.BasicURLHandler.upload(BasicURLHandler.java:264)
at org.apache.ivy.util.url.URLHandlerDispatcher.upload(URLHandlerDispatcher.java:82)
at org.apache.ivy.util.FileUtil.copy(FileUtil.java:150)
at org.apache.ivy.plugins.repository.url.URLRepository.put(URLRepository.java:84)
at org.apache.ivy.plugins.repository.AbstractRepository.put(AbstractRepository.java:130)
at org.apache.ivy.plugins.resolver.RepositoryResolver.put(RepositoryResolver.java:234)
at org.apache.ivy.plugins.resolver.RepositoryResolver.publish(RepositoryResolver.java:216)
at org.apache.ivy.core.publish.PublishEngine.publish(PublishEngine.java:275)
at org.apache.ivy.core.publish.PublishEngine.publish(PublishEngine.java:254)
at org.apache.ivy.core.publish.PublishEngine.publish(PublishEngine.java:166)
at org.apache.ivy.Ivy.publish(Ivy.java:615)
at org.apache.ivy.ant.IvyPublish.doExecute(IvyPublish.java:312)
at org.apache.ivy.ant.IvyTask.execute(IvyTask.java:277)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291)
at sun.reflect.GeneratedMethodAccessor4.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106)
at org.apache.tools.ant.Task.perform(Task.java:348)
at org.apache.tools.ant.Target.execute(Target.java:390)
at org.apache.tools.ant.Target.performTasks(Target.java:411)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399)
at org.apache.tools.ant.Project.executeTarget(Project.java:1368)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1251)
at org.apache.tools.ant.Main.runBuild(Main.java:809)
at org.apache.tools.ant.Main.startAnt(Main.java:217)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:280)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:109)
impossible to publish artifacts;
PUT operation to URL http://myserver.com/repository/com.mycompany/projectA/1.0/ivy-1.0.xml failed with status code 405: Method Not Allowed
ivy.xml
<ivy-module version="2.0">
<info organisation="com.mycompany" module="projectA" revision="${version}">
<description>
This project provides interface to projectA.
</description>
</info>
<publications>
<artifact />
</publications>
<dependencies defaultconfmapping="*->*,!sources,!javadoc">
<dependency org="com.hazelcast" name="hazelcast-client" rev="2.5" transitive="false"/>
<dependency org="com.hazelcast" name="hazelcast" rev="3.1.5" transitive="false"/>
<dependency org="log4j" name="log4j" rev="1.2.16" transitive="false"/>
</dependencies>
</ivy-module>
ivysettings.xml
<ivysettings>
<settings defaultResolver="defaultresolver" />
<property name="ibiblio-maven2-root" value="http://repo1.maven.org/maven2/" />
<property name="build-server" value="http://myserver.com/repository" />
<resolvers>
<chain name="defaultresolver">
<ibiblio name="local" m2compatible="true" root="${build-server}" />
<url name="repository">
<ivy pattern="${build-server}/[organisation]/[module]/[revision]/ivy-[revision].xml" />
<artifact pattern="${build-server}/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
</chain>
</resolvers>
</ivysettings>
build.xml
<ivy:publish artifactspattern="${build.dir}/[artifact].[ext]"
resolver="repository" organisation="com.mycompany"
module="projectA" pubrevision="${version}" status="release" conf="java" />
I had the same error message trying to publish to Artifactory. It turned out I forgot to include the port 8081 in the URL.
what is your HTTP Server? Did you use Something like Artifactory?
If you are using Apache, the PUT operation is disabled by default (maybe the same for most Web servers). You'll have to enable it and associate a backend script to handle the query as expected (retrieving artifacts from query and saving them on file system).
I enable it using PHP, you can see how from my GitHub repository: https://github.com/opatry/ivy-frontend
if you are using Artifactory as your repository, check this out:
http://www.jfrog.com/confluence/display/RTF2X/Working+with+Ivy
The ivy settings should change the build-server property
<ivysettings>
<settings defaultResolver="defaultresolver" />
<property name="ibiblio-maven2-root" value="http://repo1.maven.org/maven2/" />
<property name="build-server" value="http://myserver.com/repository/libs-snapshot-local/" />
<resolvers>
<chain name="defaultresolver">
<ibiblio name="local" m2compatible="true" root="${build-server}" />
<url name="repository">
<ivy pattern="${build-server}/[organisation]/[module]/[revision]/ivy-[revision].xml" />
<artifact pattern="${build-server}/[organisation]/[module]/[revision]/[artifact]-[revision].[ext]" />
</url>
</chain>
</resolvers>
</ivysettings>
I'm using a ODataController to return data to the breeze dataservice, this is the dataservice
app.dataservice = (function (breeze) {
breeze.config.initializeAdapterInstances({ dataService: "OData" });
var manager = new breeze.EntityManager('/api/v1/');
return {
getRecipePage: getRecipePage
};
function getRecipePage(skip, take, searchText) {
var query = breeze.EntityQuery
.from("Recipes")
.orderBy("Name")
.skip(skip).take(take)
.inlineCount(true);
if (searchText) {
query = query.where("Name", "contains", searchText);
}
return manager.executeQuery(query);
}
})(breeze);
when calling the getRecipePage function in my controller, it seems to return data properly, but the exceptions is strange
getDataFunction(skip, take)
.then(function (largeLoad) {
$scope.setPagedData(largeLoad, currentPage, pageSize);
})
.fail(function (e) {
debugger;
});
The e variables has the message "; ", which makes no sense. The status is "200 OK" which is good.
The body contains my two entities and the url appers correct "/api/v1/Recipes?$orderby=Name&$top=2&$inlinecount=allpages", if I navigate to it, the json looks good:
{
"$id": "1",
"$type": "Breeze.WebApi2.QueryResult, Breeze.WebApi2",
"Results": [
{
"$id": "2",
"$type": "RecipeBook.Web.Angular.Models.RecipeBook.Recipe, RecipeBook.Web.Angular",
"Name": "1 Boiled Water",
"Description": "6 Steamy goodness!",
"Id": 1
},
{
"$id": "3",
"$type": "RecipeBook.Web.Angular.Models.RecipeBook.Recipe, RecipeBook.Web.Angular",
"Name": "2 Hot Chocolate",
"Description": "5 Chocolatey Chocolateness!",
"Id": 2
}
],
"InlineCount": 6
}
...what is this error? Lastly, here is the stack:
Error
at createError (http://localhost:62576/Scripts/breeze.debug.js:15182:22)
at http://localhost:62576/Scripts/breeze.debug.js:14971:40
at http://localhost:62576/Scripts/datajs-1.1.1.js:1671:17
at XMLHttpRequest.odata.defaultHttpClient.request.xhr.onreadystatechange (http://localhost:62576/Scripts/datajs-1.1.1.js:2587:25)
Thoughts as to what is going on???
EDIT:
After a ton of digging, I've somewhat narrowed down the issue to be related to the handler that reads the response. In datajs-1.1.1.js ~line 8100 there is a dispatchHandler function. I have a requestOrResponse that came back from the OData call:
It has a body property with the above json text. The data property is undefined however, but I think that's what it's trying to translate the body into...and is looking for a handler to do so. It's statusCode is 200, and statusText is OK. But the method doesn't find an appropriate handler and throws:
throw { message: "no handler for data" };
...this appears to be where the error originates. I just have no clue what's not setup correctly so that I can remedy the situation.
EDIT2:
It might actually be caused because the metadata (xml) isn't being parsed correctly..., this is what it looks like (taken from the datajs handlerRead function while debugging)
<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx">
<edmx:DataServices m:DataServiceVersion="3.0" m:MaxDataServiceVersion="3.0" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata">
<Schema Namespace="RecipeBook.Web.Angular.Models.Recipe" xmlns="http://schemas.microsoft.com/ado/2009/11/edm">
<EntityType Name="Recipe">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int32" Nullable="false" />
<Property Name="Name" Type="Edm.String" />
<Property Name="Description" Type="Edm.String" />
<Property Name="Steps" Type="Collection(Edm.String)" />
<NavigationProperty Name="Ingredients" Relationship="RecipeBook.Web.Angular.Models.Recipe.RecipeBook_Web_Angular_Models_Recipe_Recipe_Ingredients_RecipeBook_Web_Angular_Models_Recipe_RecipeIngredient_IngredientsPartner" ToRole="Ingredients" FromRole="IngredientsPartner" />
</EntityType>
<EntityType Name="RecipeIngredient">
<Key>
<PropertyRef Name="Id" />
</Key>
<Property Name="Id" Type="Edm.Int32" Nullable="false" />
<Property Name="IngredientId" Type="Edm.Int32" Nullable="false" />
<Property Name="Quantity" Type="Edm.Int32" Nullable="false" />
<Property Name="UnitOfMeasureId" Type="Edm.Int32" Nullable="false" />
<Property Name="Notes" Type="Edm.String" />
</EntityType>
<Association Name="RecipeBook_Web_Angular_Models_Recipe_Recipe_Ingredients_RecipeBook_Web_Angular_Models_Recipe_RecipeIngredient_IngredientsPartner">
<End Type="RecipeBook.Web.Angular.Models.Recipe.RecipeIngredient" Role="Ingredients" Multiplicity="*" />
<End Type="RecipeBook.Web.Angular.Models.Recipe.Recipe" Role="IngredientsPartner" Multiplicity="0..1" />
</Association>
<EntityContainer Name="Container" m:IsDefaultEntityContainer="true">
<EntitySet Name="Recipes" EntityType="RecipeBook.Web.Angular.Models.Recipe.Recipe" />
</EntityContainer>
</Schema>
</edmx:DataServices>
</edmx:Edmx>
EDIT3:
...so, if I use OData, as my dataService I need json metadata found at $metadata. If I use WebAPI it looks for metadata at /Metadata, and this can be Edmx or json. However, my metadata is returned as Edmx at $metadata ... which is the one thing not supported?
http://www.breezejs.com/documentation/breeze-metadata-details
I'm about to throw all this out (angular, breeze, odata) and just do it the old way.
Edit4:
This isn't a fix, but if I turn off metadata it "works"...so my issue is definitely related to Metadata not loading properly.
var dataService = new breeze.DataService({
serviceName: "/api/v1/",
hasServerMetadata: false
});
It looks like you are using Web API. Consider that you could decorate your controllers with the [BreezeController] attribute and instead of specifying OData you could use webApi which extends the configuration a bit. It's worth trying.
Also you probably need to configure the Breeze adapter to use backingStore which pairs well with Angular. - http://www.breezejs.com/samples/todo-dataservice (this link has some helpful tips to guide you through setting up Breeze to work well with Angular)
Last, remember that setting up any library the first time you use it always seems more difficult than it really is. Once you get it configured you almost never touch configuration again and instead Breeze just works and is really awesome.
EDIT
Check this link which has a brief walk-thru on Breeze, Angular, OData, and Web API - http://sravi-kiran.blogspot.com/2013/11/UsingBreezeJsToConsumeAspNetWebApiODataInAnAngularJsApplication.html
Another good 'How do I...' answer here by Ward -
How to consume OData service with Html/Javascript?
Does anyone know, or better yet have an example, of a WCF service that will accept a form post encoded multipart/form-data ie. a file upload from a web page?
I have come up empty on google.
Ta, Ant
So, here goes...
Create your service contract which an operation which accepts a stream for its only parameter, decorate with WebInvoke as below
[ServiceContract]
public interface IService1 {
[OperationContract]
[WebInvoke(
Method = "POST",
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "/Upload")]
void Upload(Stream data);
}
Create the class...
public class Service1 : IService1 {
public void Upload(Stream data) {
// Get header info from WebOperationContext.Current.IncomingRequest.Headers
// open and decode the multipart data, save to the desired place
}
And the config, to accept streamed data, and the maximum size
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="WebConfiguration"
maxBufferSize="65536"
maxReceivedMessageSize="2000000000"
transferMode="Streamed">
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Sandbox.WCFUpload.Web.Service1Behavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Sandbox.WCFUpload.Web.Service1" behaviorConfiguration="Sandbox.WCFUpload.Web.Service1Behavior">
<endpoint
address=""
binding="webHttpBinding"
behaviorConfiguration="WebBehavior"
bindingConfiguration="WebConfiguration"
contract="Sandbox.WCFUpload.Web.IService1" />
</service>
</services>
</system.serviceModel>
Also in the System.Web increase the amount of data allowed in System.Web
<system.web>
<otherStuff>...</otherStuff>
<httpRuntime maxRequestLength="2000000"/>
</system.web>
This is just the basics, but allows for the addition of a Progress method to show an ajax progress bar and you may want to add some security.
I don't exactly know what you're trying to accomplish here, but there's no built-in support in "classic" SOAP-based WCF to capture and handle form post data. You'll have to do that yourself.
On the other hand, if you're talking about REST-based WCF with the webHttpBinding, you could certainly have a service methods that is decorated with the [WebInvoke()] attribute which would be called with a HTTP POST method.
[WebInvoke(Method="POST", UriTemplate="....")]
public string PostHandler(int value)
The URI template would define the URI to use where the HTTP POST should go. You'd have to hook that up to your ASP.NET form (or whatever you're using to actually do the post).
For a great introduction to REST style WCF, check out Aaron Skonnard's screen cast series on the WCF REST Starter Kit and how to use it.
Marc