elemental2.dom.PushSubscription (v2.25, July 2019) has endpoint but not p256dh and auth keys, anyone know how to access these?
Any help greatly appreciated.
Phil.
You can do this, but note that this is not included in elemental2 because it is a Firefox-only method (actually looks like it is already supported in most browsers, although here said that it is Firefox-only).
{
PushSubscription subscription = …;
FirefoxPushSubscription firefoxPushSubscription = Js.cast(subscription);
}
#JsType(isNative = true, name = "PushSubscription", namespace = JsPackage.GLOBAL)
public static class FirefoxPushSubscription extends PushSubscription {
public native ArrayBuffer getKey(String name);
}
Related
I try to figure out, how to update a virtual document with my own custom Provider, which I have opened in an editor. I neither understand the docu at https://code.visualstudio.com/api/extension-guides/virtual-documents#update-virtual-documents nor the example at https://github.com/microsoft/vscode-extension-samples/tree/master/contentprovider-sample
I tried to hack something like the following:
class MyProvider implements vscode.TextDocumentContentProvider {
public onDidChangeEmitter = new vscode.EventEmitter<vscode.Uri>();
onDidChange = this.onDidChangeEmitter.event;
public static instance: LocalChangesProvider | undefined;
public constructor() {
LocalChangesProvider.instance = this;
}
provideTextDocumentContent(uri: vscode.Uri) {
return someGlobal.text;
}
}
someGlobal.text = 'other text';
MyProvider.instance.onDidChangeEmitter.fire(myUriSchema);
But it seems I am missing something. I am kind of frustrated, that I am too stupid to simply notify vscode to update my own virtual document :/ Any help is appreciated :)
While working for a minimal full example I noticed, that the myUriSchema must match the title / path of the opened document, meaning:
const documentUriToUpdate = vscode.Uri.parse(myUriSchema + ':' + myTitle);
MyProvider.instance.onDidChangeEmitter.fire(documentUriToUpdate )
P.S.:
From a design perspective this instance-hack of mine definitely wins no price - just for PoC how it works :)
Using StatefulKnowledgeSession I'm able to define a filter which describes the rules I want to execute:
session.fireAllRules(new RuleNameEqualsAgendaFilter(ruleName));
But I couldn't find a way to do same thing using StatelessKnowledgeSession:
cmds.add(CommandFactory.newFireAllRules());
ExecutionResults results = session.execute(CommandFactory.newBatchExecution(cmds));
CommandFactory.newFireAllRules() can take int max and String outIdentifier or no parameter at all.
Excessive(!) documentation of JBoss Drools doesn't help me either:
Documentation
My question is whether this is possible or not.
Thanks.
The CommandFactory doesn't have methods for creating a FireAllRulesCommand using filters, but you can just create one yourself:
List<Command> cmds = new ArrayList<Command>();
cmds.add(CommandFactory.newInsert(new MyFact()));
cmds.add(new FireAllRulesCommand(new RuleNameEqualsAgendaFilter("MyRule")));
ExecutionResults results = ksession.execute(CommandFactory.newBatchExecution(cmds));
private static class RuleNameEqualsAgendaFilter implements AgendaFilter {
private final String ruleName;
public RuleNameEqualsAgendaFilter(final String ruleName) {
this.ruleName = ruleName;
}
public boolean accept(final Activation activation) {
return activation.getRule().getName().equals(this.ruleName);
}
}
I've tried to learn the JSF 2.0 by implementing the managed bean via the NetBeans 7. By overview it contains the property as a data object which implements the interface as the following: -
public interface MyInterface1 {
void setName(String name);
String getName();
}
public interface MyInterface2 extends MyInterface1 {
void setPhone(String phone);
String getPhone();
}
public class MyInfo implements MyInterface2 {
//...Getter, Setter
}
#ManagedBean(name="myBean")
public class MyManagedBean {
private MyInfo myInfo = new MyInfo();
//..Getter, Setter
}
When I enter the EL at the JSF/XHTML as
#{myBean.myInfo....}
the methods which are defined at the Super Interface, the MyInterface1 is not displayed.
I'm not sure if it is a tool limitation or I may do something wrong or not.
Could you please help to advise further? Thank you very much for your help in advance. I'm looking forward to hearing from you soon.
Regards,
Charlee Ch.
This is definitely a limitation of the Netbeans editor. I've constantly struggled with similar issues in NB 6.9, code completion would sometimes not work at all, sometimes missing out interfaces/methods, etc. But hey, you can go ahead and type in the method name yourself - it should work.
I register in container services implementing IMyService.
Do I have any guarantees about their order in
container.Resolve<IEnumerable<IMyService>>
?
Just as extra help for people like me landing on this page... Here is an example how one could do it.
public static class AutofacExtensions
{
private const string OrderString = "WithOrderTag";
private static int OrderCounter;
public static IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle>
WithOrder<TLimit, TActivatorData, TRegistrationStyle>(
this IRegistrationBuilder<TLimit, TActivatorData, TRegistrationStyle> registrationBuilder)
{
return registrationBuilder.WithMetadata(OrderString, Interlocked.Increment(ref OrderCounter));
}
public static IEnumerable<TComponent> ResolveOrdered<TComponent>(this IComponentContext context)
{
return from m in context.Resolve<IEnumerable<Meta<TComponent>>>()
orderby m.Metadata[OrderString]
select m.Value;
}
}
No, there's no ordering guaranteed here. We've considered extensions to enable it but for now it's something to handle manually.
I don't mean to self-promote, but I have also created a package to solve this problem because I had a similar need: https://github.com/mthamil/Autofac.Extras.Ordering
It uses the IOrderedEnumerable<T> interface to declare the need for ordering.
I know this is an old post but to maintain the order of registration, can't we just use PreserveExistingDefaults() during registration?
builder.RegisterInstance(serviceInstance1).As<IService>().PreserveExistingDefaults();
builder.RegisterInstance(serviceInstance2).As<IService>().PreserveExistingDefaults();
// services should be in the same order of registration
var services = builder.Resolve<IEnumberable<IService>>();
I didn't find any fresh information on topic and wrote a test which is as simple as (you'd better write your own):
var cb = new ContainerBuilder();
cb.RegisterType<MyClass1>().As<IInterface>();
// ...
using (var c = cb.Build())
{
using (var l = c.BeginLifetimeScope())
{
var e = l.Resolve<IEnumerable<IInterface>>().ToArray();
var c = l.Resolve<IReadOnlyCollection<IInterface>>();
var l = l.Resolve<IReadOnlyList<IInterface>>();
// check here, ordering is ok
}
}
Ordering was kept for all cases I've come up with. I know it is not reliable, but I think that in the current version of Autofac (4.6.0) ordering is wisely kept.
Some I do quite a lot of is read integers from AppSettings. What's the best way to do this?
Rather than do this every time:
int page_size;
if (int.TryParse( ConfigurationManager.AppSettings["PAGE_SIZE"], out page_size){
}
I'm thinking a method in my Helpers class like this:
int GetSettingInt(string key) {
int i;
return int.TryParse(ConfigurationManager.AppSettings[key], out i) ? i : -1;
}
but this is just to save some keystrokes.
Ideally, I'd love to put them all into some kind of structure that I could use intellisense with so I don't end up with run-time errors, but I don't know how I'd approach this... or if this is even possible.
What's a best practices way of getting and reading integers from the AppSettings section of the Web.Config?
ONE MORE THING...
wouldn't it be a good idea to set this as readonly?
readonly int pageSize = Helpers.GetSettingInt("PAGE_SIZE") doesn't seem to work.
I've found an answer to my problem. It involves extra work at first, but in the end, it will reduce errors.
It is found at Scott Allen's blog OdeToCode and here's my implementation:
Create a static class called Config
public static class Config {
public static int PageSize {
get { return int.Parse(ConfigurationManager.AppSettings["PAGE_SIZE"]); }
}
public static int HighlightedProductId {
get {
return int.Parse(ConfigurationManager.AppSettings["HIGHLIGHT_PID"]);
}
}
}
Advantage of doing this are three-fold:
Intellisense
One breakpoint (DRY)
Since I only am writing the Config String ONCE, I do a regular int.Parse.
If someone changes the AppSetting Key, it will break, but I can handle that, as those values aren't changed and the performance is better than a TryParse and it can be fixed in one location.
The solution is so simple... I don't know why I didn't think of it before. Call the values like so:
Config.PageSize
Config.HighlightedProductId
Yay!
I know that this question was asked many years ago, but maybe this answer could be useful for someone. Currently, if you're already receiving an IConfiguration reference in your class constructor, the best way to do it is using GetValue<int>("appsettings-key-goes-here"):
public class MyClass
{
private readonly IConfiguration _configuration;
public MyClass(IConfiguration configuration)
{
_configuration = configuration;
}
public void MyMethod()
{
int value = _configuration.GetValue<int>("appsettings-key-goes-here");
}
}
Take a look at T4Config. I will generate an interface and concrete implementation of your appsettings and connectionstringsections of you web/app config using Lazyloading of the values in the proper data types. It uses a simple T4 template to auto generate things for you.
To avoid creating a bicycle class you could use the following:
System.Configuration.Abstractions.AppSettings.AppSetting<int>("intKey");
https://github.com/davidwhitney/System.Configuration.Abstractions